xaxxon
xaxxon

Reputation: 19771

In the V8 Javascript Engine, how do you add a FunctionTemplate as an attribute of another FunctionTemplate with the C++ API?

I have a function set up to return a wrapped C++ object when called as

new MyClass();

but I want to also be able to say

MyClass.do_something();

I know how to do what I want in pure javascript:

MyClass.prototype = { do_something: function(){}};

but how do I do the same in C++?

I'm aware of the InstanceTemplate() and PrototypeTemplate() methods on v8::FunctionTemplate, but those seem to only be used in the creation of the new object returned when new MyClass() is called. How do I get at the actual function's prototype?

Thank you.

I saw this post, but am not sure if it's relevant: Add a function template to a global object prototype in v8

Upvotes: 3

Views: 620

Answers (1)

xaxxon
xaxxon

Reputation: 19771

Turns out I was way overthinking the problem.

You simply call .Set() on your v8::FunctionTemplate and pass in another v8::FunctionTemplate as the value.

my_constructor_function_template.Set("static_method_name", static_method_function_template);

Upvotes: 2

Related Questions