call/apply的第一个参数如果为null。this指向window

call/apply是用来改变函数的作用域的,第一次参数为this,第二个参数为传输的值,例如

    var a ="windowA";
    var b = "windowB";
    var str = "str";
    var myObject = {a:"myA",b:"myB"};
    function hello(s){
        alert("a= "+this.a + ", b= "+this.b+" "+s);
    }
    hello.call(null,str);//a ="windowA" b = "windowB" str
    hello.call(myObject,str);//a="myA" b="myB" str

如果第一个参数为null,则this指向window(在node环境中则指向global)

hello.call(null)//this 指向window
hello.call(window)//this同样指向window
原文地址:https://www.cnblogs.com/lijinwen/p/5769410.html