我是靠谱客的博主 踏实雪碧,这篇文章主要介绍js arguments对象应用介绍,现在分享给大家,希望可以做个参考。

在javascript中,不需要明确指出参数名,就能访问它们。如:

复制代码 代码如下:

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

用arguments[0]可以访问第一个参数,如此类推。

利用arguments对象可以实现重载,利用arguments.length可以获取函数的参数个数,如下:
复制代码 代码如下:

function hi(){
if(arguments.length==1){
alert(arguments[0]);
}
else if(arguments.length==2){
alert(arguments[0] + arguments[1]);
}
}

最后

以上就是踏实雪碧最近收集整理的关于js arguments对象应用介绍的全部内容,更多相关js内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(198)

评论列表共有 0 条评论

立即
投稿
返回
顶部