The difference between call, apply, bind,

Both apply and call exist
to change the context of a function at runtime (just to change the point of this inside the function);

If you use the apply or call methods, then this points to their first parameter, and the second parameter of apply is an array of parameters. The second and subsequent parameters of call are all elements in the array, which means that you must enumerate all of them. come out;

bind() also changes the point of this in the function body;

bind will create a new function, called the binding function. When this function is called, the binding function will use the first parameter passed to the bind() method when creating it as this, and then pass it into the bind() method. The two and later parameters plus the parameters of the binding function at runtime are used as the parameters of the original function in order to call the original function;

The biggest difference between bind and apply and call is: bind will not be called immediately, the other two will be called immediately

The difference between the three uses:
they are used to change the direction of the this object of the function; the
first parameter is the object that this points to;
both can use subsequent parameters to pass parameters;
bind returns the corresponding function, which is convenient for later calling. Apply and call are called immediately; apply and call exist to change the context of a function at runtime (that is, to change the point of this inside the function);

If you use the apply or call methods, then this points to their first parameter, and the second parameter of apply is an array of parameters. The second and subsequent parameters of call are all elements in the array, which means that you must enumerate all of them. come out;

bind()-also changes the point of this in the function body;

bind will create a new function, called the binding function. When this function is called, the binding function will use the first parameter passed to the bind() method when creating it as this, and then pass it into the bind() method. The two and later parameters plus the parameters of the binding function at runtime are used as the parameters of the original function in order to call the original function;

The biggest difference between bind and apply and call is: bind will not be called immediately, the other two will be called immediately

The difference between the three uses:
they are used to change the direction of the this object of the function; the
first parameter is the object that this points to;
both can use subsequent parameters to pass parameters;

bind returns the corresponding function, which is convenient for later calling. apply and call are called immediately ;

Guess you like

Origin blog.csdn.net/weixin_48895522/article/details/109521388