MongoDB から取得した新しいデータでオブジェクト プロパティを更新しようとしています。次のコードは機能しません。どうしてか分かりません?誰でも私を助けることができますか?
var UserDB = require('../models/user_model.js').UserModel;
function User(uid, username, credit, socket, seat, normal, bank, bankThree) {
this.uid = uid;
this.username = username;
this.credit = credit;
this.socket = socket;
this.seat = seat;
this.normal = normal;
this.bank = bank;
this.bankThree = bankThree;
this.serverPerform = 0;
this.actionTaken = false;
this.cards = [];
this.bet = 0;
this.catched = false;
this.action = false;
}
User.prototype.update = function(){
var self = this;
UserDB.findOne({uid:this.uid},function(err,doc){
console.log(doc);
if(!err){
self.username = doc.username;
self.credit = doc.credit;
console.log(self); // work as expected
}
});
console.log(self); // nothing change
};
var user = new User(1);
user.update(); //nothing change