var a = {
text : 3,
logText : function () {
console.log(this.text);
},
callLogText : function() {
logText();
}
};
a.callLogText();
这将生成一条ReferenceError: logText is not defined
错误消息。
相反,你this
给logText()
方法加上前缀,就可以了。不会弹出错误消息。
var a = {
text : 3,
logText : function () {
console.log(this.text);
},
callLogText : function() {
this.logText();
}
};
我实在想不通原因。