在c++中继承JavaScript函数
Inheriting from JavaScript function in C++
我有一个下面的JavaScript基本函数:
function Animal { }
Animal.prototype.move = function () {
//...
}
我也有一个派生的JavaScript函数,像这样:
function Dog {
Dog.super_.call(this);
}
util.inherits(Dog, Animal);
Dog.prototype.bark = function () {
// ...
}
现在我想创建一个c++插件,它与派生的插件完全相同Dog
JavaScript函数
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
函数模板中继承它?或者我应该赋值animalFunc。Prototype 到tpl.prototype
唉,你不能。
查看此讨论:https://github.com/nodejs/node-addon-api/issues/229
相关文章:
- 我可以使用谷歌 v8 在回调函数中获取 JavaScript 函数C++源文本吗?
- 如何在 C++ 中从 V8 调用 Javascript 函数
- 如何使用 cocos creator 在 Cocos2d-X/Cocos2d-JS 中调用 javascript 函数并
- 如何使用 JavaScriptCore 将C++对象传递给 JavaScript 函数
- v8.从 C++ 保存和调用 JavaScript 函数
- Javascript 函数作为从 c++ 定义的 QML 属性
- 在Linux上,用BASH脚本或C 脚本替换JavaScript函数
- 在WindBG断点命令中调用JavaScript函数
- C ++ tiny-js 从外部文件执行 JavaScript 函数
- 在 V8 中创建自定义 JavaScript 函数
- 在V8中从C++回调调用Javascript函数
- 从QT调用JavaScript函数,并未显示输出
- 从多线程C++插件回调NodeJS Javascript函数
- 使用参数从 c++ 调用 v8 JavaScript 函数
- 使用 Emscripten 异步调用 JavaScript C++函数
- 从 C++ 节点调用 JavaScript 函数.js扩展
- ActiveX 调用 Javascript 函数
- 从C++调用javascript函数
- 在没有 MFC 的情况下从C++运行 JavaScript 函数
- 在c++中继承JavaScript函数