js implements call, apply, bind

The role of call and apply is to return the result of the function, change this point, the difference with apply is that call can pass multiple parameters, apply can only be passed into the array.

The role of bind is to change this to return a new function.

If you do not pass in any parameters, implement a call

 

 In the case of incoming parameters, it is relatively simple to implement with es6 and easy to understand

 

It's a little more complicated without es6

 

 

 apply is implemented in a similar way

 

 

bind returns a new function

 

 

 

Guess you like

Origin www.cnblogs.com/cool-wan/p/12760029.html