argument is a special parameter of a function in JavaScript, such as the following, using argument access function parameters to determine whether the function executes
Copy Code code as follows:
<script type= "Text/javascript" >
function SayHello () {
if (arguments[0] = = "Bye")
Return
Else
Alert ("Hello" + arguments[0]);
}
</script>
The length property of the argument can be used to return the number of parameters.
Copy Code code as follows:
<script type= "Text/javascript" >
function Cnumbarg () {
return arguments.length;
}
document.write (Cnumbarg (25,2255, "hello") + "<br>");/return 3
document.write (Cnumbarg () + "<br>");//0
document.write (Cnumbarg (1111) + "<br>");//1
</script>
Using argument objects to simulate overloads of functions
Copy Code code as follows:
<script type= "Text/javascript" >
function Fnadd () {
if (arguments.length = 0)
Return
else if (arguments.length = 1)
return arguments[0] + 5;
Else (Arguments.length >1)
var isum =0
for (var i=0;i< arguments.length;i++)
Isum + = Arguments[i];
return isum;
}
document.write (Fnadd (5) + "<br>");
document.write (Fnadd) + "<br>");
document.write (Fnadd (10,20) + "<br>");
document.write (Fnadd (10,20,30,40) + "<br>");
</script>
Small partners are not argument have a new understanding of it, in fact, he can do more things, children's shoes themselves think more do try.