【发布时间】:2014-02-28 15:06:11
【问题描述】:
因为数据库本身就是一个单独的对象,所以调用它我输了this
var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://localhost:7474');
function MyObject(id){this.id = id}
MyObject.prototype.myQuery = function(){
db.query('Some Query',{args:params},function(callback){
//this in here is some neo4j db related object.
//instead of MyObject
console.log(this.id); //undefined
});
}
myObject = new MyObject(9);
myObject.myQuery(); //undefined
任何解决方法来进行数据库调用并且仍然让我的this 引用数据库回调内部的原始预期对象?
【问题讨论】:
标签: javascript node.js neo4j