"Front-end Learning notes" function definition, function call, this

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.