The difference between apply, call and bind in JS

apply、call、bind

1: role

Change the context of the function runtime, that is, change the pointing problem of this.

xxxFunction.call(this,arg1,arg2,arg3);
xxxFunction.apply(this,[arg1,arg2,arg3]);
xxxFunction.bind(this,arg1,arg2,arg3);

 

2: Difference

apply or call method, then this points to their first parameter, the second parameter of apply is an array of parameters, and the second and subsequent parameters of call are all elements in the array, that is to say, they should all be listed;

The biggest difference between bind and apply and call is that bind will not be called immediately, and the other two will be called immediately. If you call bind multiple times, the number of times that comes out is invalid.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326220190&siteId=291194637