The difference between the three methods of call(), apply() and bind() of the front-end study notes (19)

call()

Syntax:
fn.call()
obj.fn.call()
Parameters: the
first parameter, which is the this inside the function, points to the
start of the second parameter, and passes parameters to the function in turn.
Features: the
function will be executed immediately (not suitable for timing (Processor processing function or event processing function)
Role:
Pseudo-array borrows array method

apply()

Syntax:
fn.apply()
obj.fn.apply()
Parameters: the
first parameter, which points to this inside the function. The
second parameter: either an array or a pseudo-array, and each item in it is passed to the function in turn Parameters
Features: The
function will be executed immediately.
Role: You can pass parameters to certain functions in the form of an array,
such as Math.max()

bind()

To use, just connect it directly and use it after the function name.
Syntax:
fn.apply()
obj.fn.apply()
Parameters: the
first parameter. It is the this point inside the function.
Starting from the second parameter, pass parameters to the function in turn
Features:
Will not call the function immediately
will return a new function, a function that has been changed to this point
Role: Change the this point of the
event processing function or timer processing function

Guess you like

Origin blog.csdn.net/qq_42698576/article/details/108109960