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.