When should I use call() vs invoking the function directly?

后端 未结 6 2275
小蘑菇
小蘑菇 2021-02-19 05:14

I\'ve got a JavaScript application that uses a lot of callbacks. A typical function will take a callback, and wrap it with another callback.

Namespace.foo = func         


        
6条回答
  •  执笔经年
    2021-02-19 05:41

    The only reason to use call (or apply) is if you want to set the value of this inside the function.

    Well, I guess apply can be useful in other cases as it accepts an array of parameters.

提交回复
热议问题