你能向我解釋爲什麼這段代碼顯示錯誤,並且不打印任何東西嗎?此代碼不打印任何內容
var myObject = {
test: "bar",
myfunc: function() {
var self = this;
console.log("outer myfunc: this.test = " + this.test);
console.log("outer myfunc: self.test = " + self.test);
(function() {
console.log("inner myfunc: this.test = " + this.test);
console.log("outer myfunc: self.test = " + self.test);
}());
}
};
它沒有錯誤編譯成功,但運行後,僅打印未定義的字符串
你能顯示你的函數調用代碼嗎? –
你是什麼意思編譯? JS解釋! –
你在哪裏/如何調用你的函數?這個代碼本身並沒有做任何事情。 –