(function?Foo(){
????this.num=123;
????console.log(this);//window
????(function?fn1(){
????????console.log(this)//window
????}());
})();函數(shù)Foo是在全局環(huán)境下調(diào)用的所以this指向window,但是為什么函數(shù)fn1是在Foo里面調(diào)用的,也是指向window.function?Foo(){
????this.num=123;
????console.log(this);//f
????(function?fn1(){
????????console.log(this)//window
????}());
}
var?f=new?Foo();當(dāng)Foo作為f的構(gòu)造函數(shù)時(shí),F(xiàn)oo的this指向的是f,但是為什么fn1的this還是指向window.
在函數(shù)A里再創(chuàng)建一個(gè)函數(shù)B,為什么函數(shù)B的this指向window.
thrmagic
2017-09-19 09:57:44