谁能说出为什么全局范围不适用于以下情况?为什么第 6 行打印 undefined ?外部“this”不应该在内部自动执行功能中可用吗?
var myObj = {
test1 : 4,
func : function(){
console.log(this.test1); //prints 4
(function(){
console.log("From self-executing function : " + this.test1); //prints undefined
})();
}
};
myObj.func();
其中,在以下情况下,全局范围工作正常。在外部范围内声明的 test1 在内部函数中完全可用。
var test1 = 10;
(function(){
console.log("From self-executing function : " + test1); //prints 10
})();
谁能解释一下我在这里想了解的内容?