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

Introduction to js arguments object application_basic knowledge

WBOY
Release: 2016-05-16 17:47:51
Original
1053 people have browsed it

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]);
}
}
Related labels:
js
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!