登录
登录 注册新账号
注册
已有账号登录

图片描述
这里这个this指向window,所有自调用函数里的this都指向window吗?

3 个回答

不是箭头函数 不是通过对象上挂载属性方式调用 没有bind call apply那些约束,所以你这个函数this指向了window。
按情况来判断 不要想着下死定义。

如果是严格模式下,this的值为undefined

不是,和 this 的指向规则一致。
比如这样:

new function(){
    this.name='inner';
    (()=>{console.log(this===window, this.name)})()
}
// 输出
false "inner"

指向函数实例的 this

撰写答案