Same question: http://stackoverflow.com/questions/43909594/

On Fri, May 12, 2017 at 7:40 PM, Ben Noordhuis <i...@bnoordhuis.nl> wrote:

> On Thu, May 11, 2017 at 11:02 AM, XadillaX Scarlet
> <xadillax.f...@gmail.com> wrote:
> > I know creating an ObjectTemplate and we can do several things to it.
> But my
> > question is not about those well-known things.
> >
> > I want to know how to pass the second parameter.
> >
> > As the official guide said:
> >
> > Each function template has an associated object template. This is used to
> > configure objects created with this function as their constructor.
> >
> > And the second parameter of ObjectTemplate::New is a constructor typed by
> > FunctionTemplate.
> >
> > static Local<ObjectTemplate> New(Isolate *isolate,
> Local<FunctionTemplate>
> > constructor = Local<FunctionTemplate>());
> >
> > That means something like this:
> >
> > void Constructor(const FunctionCallbackInfo<Value>& args)
> > {
> >     // ...
> > }
> >
> > Local<FunctionTemplate> _constructor = FunctionTemplate::New(isolate,
> > Constructor);
> > Local<ObjectTemplate> tpl = ObjectTemplate::New(isolate, _constructor);
> >
> > Who can give me a demo that how to implement the Constructor function.
> >
> > I tried this, but failed:
> >
> > void Constructor(const FunctionCallbackInfo<Value>& args)
> > {
> >     Isolate* isolate = args.GetIsolate();
> >     args.This()->Set(String::NewFromUtf8(isolate, "value"),
> > Number::New(isolate, 233));
> >     args.GetReturnValue().Set(args.This());
> > }
> >
> > By the way, I know the use case of accessors and so on, I just want to
> know
> > how to use the second parameter.
>
> When you say 'failed', what exactly do you mean?  Is the function not
> called or don't you see the .value property on the new object?
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to