请原谅我的javascript无知:为什么我不能在javascript中做这样的事情?运行这个告诉我没有定义theCalled。当然,功能的顺序并不重要。
var myObj = {
theCaller: function() {
console.log('The Caller');
theCalled();
},
theCalled: function() {
console.log("i was called");
}
}
myObj.theCaller();
答案 0 :(得分:1)
在你打电话之前添加“this”.theCalled()
var myObj = {
theCaller: function() {
alert('The Caller');
this.theCalled();
},
theCalled: function() {
alert("i was called");
}
}
myObj.theCaller();