Home  >  Article  >  Web Front-end  >  Introduction to js arguments object application_basic knowledge

Introduction to js arguments object application_basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:47:511055browse

In JavaScript, you can access parameter names without explicitly naming them. For example:

Copy code The code is as follows:

function hi(){
if( arguments[0]=="andy"){
return;
}
alert(arguments[0]);
}

You can use arguments[0] Access the first parameter, and so on.

Use the arguments object to implement overloading, and use arguments.length to get the number of parameters of the function, as follows:
Copy code The code is as follows:

function hi(){
if(arguments.length==1){
alert(arguments[0]);
}
else if(arguments.length==2){
alert(arguments[0] arguments[1]);
}
}
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