所以我有这个对象,我想知道在声明时如何引用其他属性:
var Chatter = function(io){
this.base_url = "http://chat.chatter.com:1337";
this.debug_on = true;
this.socket = io.connect(this.base_url);
this.socket.on('acknowledge', this.acknowledge);
}
Chatter.prototype.debug = function(msg){
if(this.debug_on){
var m = {timestamp:Date.create().format('{yyyy}-{MM}-{dd} {24hr}:{mm}:{ss}{tt}'), message:msg};
console.debug('#[ chatter DEBUG ]# - {timestamp} - {message}'.assign(m));
}
}
Chatter.prototype.acknowledge = function(data){
this.debug('Acknowledgement received!'); //This throws an error, claims #debug is not there
this.uuid = data.uuid;
};
呼叫this.debug()
失败,但在第 5 行,呼叫this.acknowledge
有效。有人可以告诉我我做错了什么吗?