JavaScript 严格模式和this

严格模式下,匿名函数内部的 this 不再是 window,而是undefined

        "use strict";

        (function(){
            console.log(this);
        })();

输出 undefined

 

使用 bind 方法修正

        "use strict";        

        (function(){
            console.log(this);
        }).bind(window)();        

输出 window

posted @ 2020-02-28 20:27  内心澎湃的水晶侠  阅读(107)  评论(0编辑  收藏  举报