This
This reference, which refers to an object, different objects, or the way the function is called, will automatically change the properties of the referenced object according to the context context of the code.
Reference rules
1, in the outermost code, this reference refers to the global object (Windows)
2, within a function, this reference differs depending on how the function is called
1) In the constructor, the object referenced by this is the object generated by the constructor
2) method invocation, this refers to the subject object
3) Appl and call invocation, the referenced object is specified by the parameters of two functions
4) Other means called, referring to the global object
Call and apply are methods of function objects
Definition of a method
Call Method:
Syntax: Call ([thisobj[,arg1[, arg2[, [,. ArgN]]])
Definition: Invokes one method of an object, replacing the current object with another object.
Description
The call method can be used to invoke a method in place of another object. The call method can change the object context of a function from the initial context to a new object specified by Thisobj.
If the Thisobj parameter is not provided, then the Global object is used as the thisobj.
Apply method:
Syntax: Apply ([Thisobj[,argarray]])
Definition: A method of applying an object that replaces the current object with another object.
Description
If Argarray is not a valid array or is not a arguments object, it will result in a TypeError.
If none of the Argarray and Thisobj parameters are provided, then the Global object is used as a thisobj and cannot be passed any parameters.
In short, there are the following differences
Func.call (FUNC1,VAR1,VAR2,VAR3) corresponding to the Apply: Func.apply (Func1,[var1,var2,var3])
callback function (callback)
function A (callback) { alert (' a '); Callback ();//or callback (), callback.apply (This) } function B () { alert (' B '); }
Call
A (b);
But most of the time the callback function has parameters, so it should be defined as follows
function A (callback) { alert (' a '); Callback.call (this, ' d ');//or callback (), callback.apply (this)
}
C (function (e) {alert (e);});
JS This,call and apply and callback functions