this的应用最后输出的结果是什么?是func?为什么?

var name="globle";
var func=function(){
    this.name="func";
    return function(){
        var that=this;
        that.name="name";
        return function(){
            return this.name
        }
    }
}
阅读 1.3k
1 个回答
var name="globle";
var func=function(){
    this.name="func";//window
    return function(){
        var that=this;//window that是传地址也是window
        that.name="name";
        return function(){
            return this.name//输出window的name
        }
    }
}

严格模式下不一样,因为 this 不会自动绑在 window 上了。

clipboard.png

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题