Function definition
Functions contain a set of statements, which are the basic module units of JavaScript and are used for code reuse, information hiding and combined calls. Functions are used to specify the behavior of objects
The four calling modes of functions and the initialization of this
The first: method calling mode
The following examples prove calling through the method calling mode , this is bound to the object that owns the method. For example:
1 2 3 4 5 6 7 8 |
|
Second type: function call mode
The following example proves that when called through the function call mode, this is bound to the global object. Such as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Third: Constructor calling mode
1 2 3 4 5 6 7 8 9 10 11 |
|
Fourth: Apply calling mode
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The difference between Apply and call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
The above is the detailed content of Detailed explanation of JavaScript function definition, calling mode and initialization example of this. For more information, please follow other related articles on the PHP Chinese website!