On the _javascript techniques of JavaScript Object model and function object

Source: Internet
Author: User

In JavaScript, a function is an object

Copy Code code as follows:

<script type= "Text/javascript" >
function Add (number) {
alert (NUMBER+20);
}
var add=function (number) {
alert (NUMBER+20);
}
function Add (number,number1) {
alert (number+30);
}
var add=function (number) {
alert (number+90);
}
Add (10);
</script>
<body>
</body>

Add is a reference, and a function is an object .

Unlike Java: there is no concept of method overloading in JavaScript. A method can have n parameters, and a parameter can pass only 1 arguments.

Data type undefined--type undefined--value

There is a function object in JavaScript, and all custom functions are function object types.
A function object receives all parameters as String types, the last of which is the body of the function, and the previous argument is the parameter that the function really needs to receive.

Copy Code code as follows:

<script type= "Text/javascript" >
var add =new Function ("number", "alert (number+20);");
Add (10);
</script>
<body>
</body>

In JavaScript, each function object has an implied object arguments, representing the arguments that are actually passed to the function.

Copy Code code as follows:

<script type= "Text/javascript" >
function Add () {
alert (arguments.length);
Alert (arguments[0]);
Alert (arguments[1]);
}
Add (10,20);
</script>
<body>
</body>

Method overloads in Java, relative to JavaScript can also be implemented by arguments.

Copy Code code as follows:

<script type= "Text/javascript" >
function Add () {
if (1==arguments.length) {
Alert (arguments[0]);
}else if (2==arguments.length) {
Alert (arguments[0]+arguments[1]);
}else if (3==arguments.length) {
Alert (arguments[0]+arguments[1]+arguments[2]);
}
}
Add (2);
Add (2,3);
Add (2,3,4);
</script>
<body>
</body>

The above is the entire content of this article, the small partners are aware of the JavaScript object model and function objects, there are questions please leave a message, we common progress.

Related Article

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.