Tag: 绑定

在Node.js和v8中调用一个使用包装对象作为参数的函数

我想在node.js中做如下的事情… var a = new A(); var b = new B(); // onTick应该是一个以B的实例作为参数的函数 a.onTick = function(bInst){….} 一个循环(); 这意味着A有一个属性“onTick”,这是一个在循环内被调用的函数。 请注意,A和B被定义为C ++封装函数,这里是定义 void AClass::Init(Handle<Object> target) { Local<FunctionTemplate> tpl = FunctionTemplate::New(New); tpl->SetClassName(String::NewSymbol("A")); tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->PrototypeTemplate()->Set(String::NewSymbol("tick"), FunctionTemplate::New(Tick)->GetFunction()); tpl->PrototypeTemplate()->Set(String::NewSymbol("loop"), FunctionTemplate::New(Loop)->GetFunction()); constructor = Persistent<Function>::New(tpl->GetFunction()); constructor->InstanceTemplate()->SetAccessor(String::New("onTick"), GetOnTick, SetOnTick); target->Set(String::NewSymbol("A"), constructor); } Handle<Value> AClass::New(const v8::Arguments &args) { HandleScope scope; AClass* acls = new AClass(); […]

async.waterfall绑定上下文

我目前正在与node.js的Web应用程序工作,我不能找出库asynchronous的上下文问题。 这里是我的应用程序的代码的一个例子: notification.prototype.save = function (callback) { async.parallel([ // Save the notification and associate it with the doodle function _saveNotification (done) { var query = 'INSERT INTO notification (notification_id, user_id, doodle_id, schedule_id) values (?, ?, ?, ?)'; notification.db.execute(query, [ this.notification_id, this.user_id, this.doodle_id, this.schedule_id ], { prepare : true }, function (err) { return done(err); }); […]