这个问题与V8 C ++ API有关。
我想从上下文中保留对javascript函数的全局引用 这不是将函数存储在本地句柄
中Local<Function> init = ...
我想将它存储在持久句柄
中Persistent<Function> init = ...
我认为这样做的正确方法是这样的:
Local<Function> l_init = ...
Persistent<Function> init = currentScope.Close(l_init);
但是 currentScope.Close()会返回一个本地句柄。 我是否可以将句柄缓存为类成员,这样我就不必每次都进行获取?
我可以将Local作为类变量,使用 currentScope.Close 进行分配,并在完成 Dispose 功能后释放它吗?
答案 0 :(得分:1)
如果您想将其存储在持久句柄中,您实际上不需要担心范围。出于本讨论的目的,关闭作用域的主要做法是将对象标记为垃圾收集。
在您的示例中,我认为您要执行以下操作:
v8::Persistent<v8::Function> init = v8::Persistent<v8::Function>::New(l_init);