在函数A里再创建一个函数B,为什么函数B的this指向window.


(function Foo(){
    this.num=123;
    console.log(this);//window
    (function fn1(){
        console.log(this)//window
    }());
})();

函数Foo是在全局环境下调用的所以this指向window,但是为什么函数fn1是在Foo里面调用的,也是指向window.

function Foo(){
    this.num=123;
    console.log(this);//f
    (function fn1(){
        console.log(this)//window
    }());
}
var f=new Foo();

当Foo作为f的构造函数时,Foo的this指向的是f,但是为什么fn1的this还是指向window.

thrmagic
浏览 1918回答 3
3回答

_游戏人生_

高程3 182页

名分开就是姓名

那你觉得b的this只向谁?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript