Three ways and characteristics of function definition:
1. function declaration; (feature: Will be pre-set; When you define a function repeatedly, the last definition is valid.) )
2. function expression;
3. function instantiation; (feature: Only local scopes and global scopes can be accessed!!!) )
/* Characteristics of the Object instantiation definition function */var person = {Name: "Andy Lau", age:50}; (function () { var person = {Name: "Andy Lau", age:30}; (function () { var person = {Name: "Andy Lau", age:10}; Console.log (person.name+person.age+ "old"); }) () })(); -and output 10-year-old Andy Lau, variable step up backwards. var person = {Name: "Andy Lau", age:50};(function () { var person = {Name: "Andy Lau", age:30}; var func = new Function ("Console.log (person.name+person.age+ ' old ');"); Func ();}) (); -If the new Function () has a 10-year-old Andy Lau, then 10-year-old, or directly 50-year-old.
Function call:
1. function call mode; Add (1)
2. method invocation mode; Mynumber.add (1)
3. constructor call pattern; New Function (...)
/* Function call mode (this) */function Add (i,j) { console.log (this);//--Window console.log (arguments);//--> [ (function () { console.log (this);//--Window }) (); var sum = i+j; return sum;} Add, var mynumber = { value:1, add:function (i) { console.log (this);//--{value:1,add: function () {}} var helper = function (i) { console.log (this);//-Window this.value + = i;//So this cannot be achieved; } Helper (i); }} Mynumber.add (1);
"Front-end Learning notes" function definition, function call, this