Home > Web Front-end > JS Tutorial > body text

arguments object_basic knowledge

WBOY
Release: 2016-05-16 19:24:18
Original
1206 people have browsed it

In JavaScript, you can access parameter names without explicitly naming them. For example:
function hi(){
if(arguments[0]=="andy"){
return;
}
alert(arguments[0]);
}
Use arguments[0] to access the first parameter, and so on.
Overloading can be achieved by using the arguments object, and the number of parameters of the function can be obtained by using arguments.length, as follows:
function hi(){
if(arguments.length==1){
alert (arguments[0]);
}
else if(arguments.length==2){
alert(arguments[0] argument[1]);
}
}
<script> <BR>function fun() <BR>{ <BR>var arr=fun.arguments; <BR>for(var i=0;i<arr.length;i++) <BR>{ <BR>alert(arr[i]); <BR>} <BR>} <BR>fun("aa","bb","cc"); <BR></script>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template