inheritanceC ++中的JavaScript函数
我有一个JavaScript的基本function:
function Animal { } Animal.prototype.move = function () { //... }
我也有一个派生的JavaScript函数,像这样:
function Dog { Dog.super_.call(this); } util.inherits(Dog, Animal); Dog.prototype.bark = function () { // ... }
现在我想创build一个与派生的Dog
JavaScript函数完全相同的C ++插件:
void Dog::Init(Handle<Object> exports, Handle<Object> module) { Isolate* isolate = Isolate::GetCurrent(); Local<Function> require = Local<Function>::Cast(module->Get( String::NewFromUtf8(isolate, "require"))); Local<Value> args[] = { String::NewFromUtf8(isolate, "./animal") }; Local<Value> animalModule = require->Call(module, 1, args); Local<Function> animalFunc = Local<Function>::Cast(animalModule); Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New); // tpl->Inherit(animalFunc); // <-- HERE tpl->SetClassName(String::NewFromUtf8(isolate, "Dog")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NODE_SET_PROTOTYPE_METHOD(tpl, "bark", Bark); constructor.Reset(isolate, tpl->GetFunction()); exports->Set(String::NewFromUtf8(isolate, "Dog"), tpl->GetFunction()); }
如何从animalFunc
/ animalModule
获取FunctionTemplate
以便能够在tpl
函数模板中inheritance它? 或者,也许我应该以某种方式将animalFunc.prototype分配给tpl.prototype ?
- 我是否应该包装一个完全包含在node.js函数中的C ++对象
- 在尝试检索时,通过nan传递数组返回未定义
- RSAloginnode.js并在C ++中validation
- C#Winforms Socket.IO到NodeJS服务器
- StackExchange NetGain vs Node.js WS websocket服务器的性能
- 如何将对象传递给V8中的JavaScriptcallback
- 编译内置c ++ 17的本地节点插件在npm安装期间失败
- 如何使用webRequest从ac#windows窗体上将file upload到node.js服务器(使用formidable)?
- 节点:符号查找错误:,未定义符号:_ZN4demo3sumEii