Apply/Call method in [removed] What is the first arguments “this”?

后端 未结 3 1848
失恋的感觉
失恋的感觉 2021-01-25 05:22

I am confused about using apply or call method correctly. I know that apply is passing an array to the function and call is passing strings to a function. For example the code b

3条回答
  •  臣服心动
    2021-01-25 05:36

    this is the scope of the Apply/Call function. An example is:

    function test() {
        alert(this.a);
    }
    
    (function () {
        this.a = "test";
        test();//test
    
        var self = this;
    
        (function () {
            this.a = "Foo";
            test();//Foo
            test.apply(self, []);//test
        }());
    
    }());
    

提交回复
热议问题