我有一个为 node.js 包装 mongodb 客户端的类。findUsers
当我打电话时,下面的类this.collection
是未定义的。
如何this.collection
从原型访问?
谢谢!
班级:
var Users;
Users = (function () {
function Users(db) {
db.collection('users', function (err, collection) {
this.collection = collection;
});
}
Users.prototype.findUsers = function (callback) {
this.collection.find({}, function (err, results) {
});
}
return Users;
})();
用法:
//db holds the db object already created
var user = new Users(db);
user.findUsers();