我有下面的结构,我不太了解输出。
var asker = {
answer: "Its raining...",
askQuestion: function(answered){
console.log("Opps..." + this.answer);
answered();
}
}
//function literal
var debunker = function(){
answer = "Its cloudy...";
debunk = function(){
console.log(this);
console.log("No way! The real answer is:" + this.answer);
};
return {
debunk: debunk
};
}();
asker.askQuestion(debunker.debunk);
它给了我这些输出
Opps...Its raining...
DOMWindow
No way! The real answer is:Its cloudy...
得到的debunker.debunk
答案是'Its cloudy'
。但是this
,在 debunk 函数中引用了对象,DOMWindow
那么如何this.answer
获取Its cloudy
它所引用的window
对象呢?