使v8对象属性和方法对JS可见
我用node::ObjectWrap
包装一个C ++对象,并且有一些定义如下的方法:
auto tpl = NanNew<v8::FunctionTemplate>(New); tpl->SetClassName(NanNew("className")); tpl->InstanceTemplate()->SetInternalFieldCount(4); NanSetPrototypeTemplate(tpl, NanNew("method1") , NanNew<v8::FunctionTemplate>(Method1) , v8::ReadOnly); NanSetPrototypeTemplate(tpl, NanNew("method2") , NanNew<v8::FunctionTemplate>(Method2), v8::ReadOnly); NanSetPrototypeTemplate(tpl, NanNew("method3") , NanNew<v8::FunctionTemplate>(Method3) , v8::ReadOnly); NanSetPrototypeTemplate(tpl, NanNew("method4") , NanNew<v8::FunctionTemplate>(Method4), v8::ReadOnly);
一切都按预期工作,我可以通过以下方式在JS中创build对象的实例:
var classInstance = new className();
所有的方法工作得很好,但是当我尝试login函数:
console.log(classInstance);
我期待看到像这样的东西:
{ method1 : [Native Function], method2 : [Native Function], method3 : [Native Function], method4 : [Native Function] }
但是我得到的是:
{}
任何想法如何使这些可见(又名enumerable)?
你有什么本质上的
var tpl = function(){}; tpl.prototype.method1 = function(){}; tpl.prototype.method2 = function(){}; tpl.prototype.method3 = function(){}; tpl.prototype.method4 = function(){}; var inst = new tpl(); console.log(tpl);
事情是打印出来的东西不包括原型链中的值。 所以inst
实际上没有任何属性可以打印,因此{}
。 只有inst.__proto__
具有属性。 属性是可枚举的,所以你可以做Object.keys(inst.__proto__);
看到他们,但他们不属于own
属性。
- 如何使用UTF-16的ICU?
- Printf语句不能在lambda上工作
- 在Unity3D C#中encryptionstring,通过HTTP GET请求作为URL参数发送,在node.js服务器中解密
- 将本地node.js扩展与支持libstd的c ++ 17链接起来
- 用混合的C / C ++源文件构build一个NodeJS插件
- 这与ObjectWrap :: Unwrap的Holder相比
- 如何用多核CPU来提高游戏服务器的性能
- 我想调用一个函数,它是从node.js javascript中写入“C”DLL的?
- nodejs native c ++ npm模块内存错误,cairoimage processing