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.
--
--
v8-users mailing list
v8-u...@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.