this全局

184 阅读1分钟

全局环境使用this,它指的就是顶层对象window

console.log(this === window); //true


    var yanzheng = ()=>{
        if(window === this){
            console.log("全局环境下,this就是指顶层的window");
        }else{
            alert("错误");
        }
    }

    yanzheng(); //全局环境下,this就是指顶层的window\