JavaScript's Function object

Source: Internet
Author: User

I have to say that Java has nothing to do with JavaScript, not the way I thought it was (JavaScript is a hyper-evolution of Java)

In JavaScript, a function is an object.

The parameter relationship between the function parameters of JavaScript and the expression calling the function is not one by one, they are a very faint relationship.

In JavaScript, there are three ways to define a function:

The first type:

1 function Add (number) 2 {3     alert (number+20); 4 }

The second type:

1 var add=function(number)2{3     alert (number+20); 4 }

The third type:

There is a function object in JavaScript, and all of the custom functions are function object types. All parameters received by a function object are of type string, where the last parameter is the body of the function to be executed, and the previous parameter is the one that the function really needs to receive.

1 var New Function ("number", "alert (number + 20);");

In JavaScript, each function has an implied object, arguments, that represents the arguments that the function actually passes. Without the concept of method (function) overloading, you can use arguments to implement overloaded functions of a function.

1 functionadd2 ()2 {3     if(1 = =arguments.length)4     {5Alert (arguments[0]);6     }7     Else if(2 = =arguments.length)8     {9Alert (Arguments[0] + arguments[1]);Ten     } One     Else if(3 = =arguments.length) A     { -Alert (Arguments[0] + arguments[1] + arguments[2]); -     } the } -  -ADD2 (3); -ADD2 (3, 4); +ADD2 (3, 4, 5);

JavaScript's Function object

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.