.call() / .apply() with NO parameters VS simply calling a function with () parenthesis

前端 未结 2 1009
深忆病人
深忆病人 2020-12-18 05:22

I\'ve seen it done differently in code out there, but is there any benefit or reason to doing a (blank params) .call / .apply over a regular ()

2条回答
  •  没有蜡笔的小新
    2020-12-18 05:55

    When you call a method with func();, this variable inside the method points to window object.

    Where as when you use call(...)/apply(...) the first parameter passed to the method call becomes this inside the method. If you are not passing any arguments/pass null or undefined then this will become global object in non strict mode.

提交回复
热议问题