如何在NodeJS插件中创build一个类返回另一个插件?

有了这个类,我可以在另一个插件的源代码中创build一个实例。 但是,如何包装对象并将其返回?

class foo : public ObjectWrap { public: int mydata; // intentionally not exposed in node foo(){ mydata = 4; } static Persistent<Function> constructor; static void Init(){ Local<FunctionTemplate> s = FunctionTemplate::New(New); s->SetClassName(String::NewSymbol("foo")); s->InstanceTemplate()->SetInternalFieldCount(1); constructor = Persistent<Function>::New(s->GetFunction()); } static Handle<Value> NewInstance() { HandleScope scope; Local<Object> in = constructor->NewInstance(); return scope.Close(in); } static Handle<Value> New(const Arguments& args) { HandleScope scope; foo* f= new foo(); f->Wrap(args.This()); return scope.Close( args.This() ); } }; 

我想要做的是,从另一个类的方法,创build一个新的实例,并返回它。

 Handle<Value> bar_method( const Arguments& args ) { HandleScope scope; // make new instace of foo foo * f = new foo(); f->mydata = 5; Handle<Object> obj = Object::New(); obj->Set( String::New("property"), f??? ); return scope.Close(obj); }