Home  >  Article  >  Web Front-end  >  arguments object_basic knowledge

arguments object_basic knowledge

WBOY
WBOYOriginal
2016-05-16 19:24:181207browse

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>

Statement:
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