JS: apply, call, bind the difference

First, what are they? We look at the call now apply:

Function.prototype methods are apply now call, so each function contains a call, apply properties.

Common: this can change the point of

Differences: different receiving function parameters manner

image

call: The first value is a function of the argument t let addEvent of this point is the object obj, then are carried addEvent function, it is necessary to list one by one

apply: The first value above, but addEvent of all arguments are placed in an array

That bind it? Its role is to point this change, but the bind or function, need to be called;

image

===============================================

Magical apply:

Scenario:

1, let Math.max () method can pick a maximum array

image

2, merge two arrays (array will change the original oh)

image

Guess you like

Origin www.cnblogs.com/hxw1024/p/12077636.html