1. About this
We need to determine the binding rules used in this function based on the "calling method" of the function on the "Call location"
2. Binding rules
(1) Default binding: This==>winow Object
(2) Implicit binding
The context object referenced by the 1.this==> function
2. Implicit loss: There is an implicit loss when a reference pass occurs: reference assignment, parameter transfer;
3. Implicit loss Solution: using hard binding (a form of displaying bindings)
(3) Explicit binding
This==> the object we specified
(4) New binding
This==> Instance Object
3. Priority level
New binding > Show Bindings > Implicit binding > Default Bindings
4. Rules under normal circumstances
(1) is the function called in new (new binding)? If so, this binds to the newly created object.
Varbar=newfoo ()
(2) is the function called by call, apply (explicit binding), or hard bind? If so, this binds to the specified object.
Varbar=foo.call (OBJ2)
(3) is the function called (implicitly bound) in a context object? If so, this binds to the context object.
Varbar=obj1.foo ()
(4) If not, use the default binding. If in strict mode, bind to undefined, otherwise bind to the global object.
Varbar=foo ()
5. Binding Exceptions
(1) In some scenarios, the binding behavior of this will be unexpected, you think you should apply the other binding rules, you may actually apply the default binding rules
(2) Soft binding: The arrow function This does not conform to our this normal binding rule
6, currying
Simply pass to the function part of the argument to invoke it, and let it return a function to handle the remaining arguments. (pre-Define some parameters)
This summary in JavaScript