Internal properties of JS inside function

Source: Internet
Author: User

1.arguments is used to store the collection of transmission parameters, can be called multiple times, each time the group is different, enhancing the robustness of the function

Instance:

Function Calc () {
var sum = 0;
/* parameter is a time */
if (arguments.length = = 1) {
sum = arguments[0]
} else if (arguments.length = = 2) {
/* When the parameter is two */
for (var i = arguments[0]; I <= arguments[1]; i++) {
sum + = i;
}
}
return sum;
}

Console.log (calc); The//calc function can be called multiple times, and the number of arguments passed in can be different.
Console.log (Calc (10, 20));

2.This iscalled by the function who is this, the method is called when the function is preceded by a window, just omitted
var person = {};
Person.name = "fangming";
Person.cals = Calcone;
var resultone = Person.cals ();

function Calcone () {
Console.log (this);//This is the value inside the person array
var sum = 0;
for (var i = 0;i <= 10;i + +) {
Sum+=i;
}
return sum
}

Internal properties of JS inside function

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.