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

后端 未结 3 1842
失恋的感觉
失恋的感觉 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

    The first argument will be the this in your function.

    ie:

    var p = {"name":"someone"};
    function myFunction(a, b) {
         console.log(this);
         return a*b;
    }
    var myArray = [10,2];
    myFunction.apply(p, myArray); //log output shows {"name":"someone"}
    

提交回复
热议问题