如何使用新版本的Node Nan Persistent

时间:2016-02-15 03:44:00

标签: c++ node.js v8 node.js-addon node.js-nan

使用Nan的新版本,以下是等效代码: 以下代码适用于0.12。*但不适用于4.3.0及更高版本。

//1)  
//This is my object_
Persistent<Object> object_;

Local<Object> obj = Nan::New<Object>();
NanAssignPersistent(object_, obj); //Don't know what to replace with here


//2)
NanDisposePersistent(object_); //Don't know what to replace with here 

1 个答案:

答案 0 :(得分:3)

nan文档显示了如何处理持久性here。查看nan tests for Persistent

也可能有用

示例:

Local<Object> obj;
Local<Object> obj2;

// Create a persistent
Nan::Persistent<v8::Object> persistent(obj);

// Get a local handle to the persisted object
v8::Local<v8::Object> orig_obj = Nan::New(persistent);

// Change the persistent reference
persistent.Reset(obj2);

// Dispose of the persistent
persistent.Reset();