The use and difference of call, apply and bind functions in js

1. Use of call function

call function calling form: call function [first parameter: the pointer of this, the parameter passing form needs to be passed one by one]


Output results

2. The use of apply function

apply function calling form [first parameter: pointer to this, parameter transfer form is an array]


Output results

3. Use of bind function

bind function calling form [the first parameter: the pointer of this, the parameter passing form needs to be passed one by one]


Output results

Summary: (1) Same: the call, apply and bind functions can all change the point of this. The first parameter of each function is passed in the object you want to modify this. The second or other parameters of the call function and bind function need to be passed one by one. (2) Differences: The value-passing forms of the call, bind and apply functions are different. The values ​​of the call and bind functions are passed one by one. The values ​​of the apply function can only be passed in the form of an array.

Guess you like

Origin blog.csdn.net/weixin_53716093/article/details/128732388