arguments的使用
当我们不确定有多少参数传递的时候,可以使用 arguments 来获取,在 JavaScript 中, arguments 实际上它是当前函数的一个内置对象。
所有的函数都内置了一个 arguments 对象,arguments 对象中 存储了传递的所有实参 。
例如:
function numMax(){
var max=arguments[0]; // arguments 中存储了numMax函数中的所有实参:23,45,96,87
for( var i=1; i<=arguments.length-1;i++){
if(arguments[i] > max){
max = arguments[i];
}
}
}
numMax(23,45,96,87);
在调用函数时,浏览器每次都会传递进两个隐含的参数:
1. 函数的上下文对象 this
2. 封装实参的对象 arguments
- arguments 是一个类数组对象,它也可以通过索引来操作数据,也可以获取长度
- 在调用函数时,我们所传递的实参都会在 arguments 中保存
- arguments . length 可以用来获取实参的长度
- 即使不定义形参,也可以通过 arguments 来使用实参,只不过比较麻烦
arguments[ 0 ] 表示第一个实参
arguments[ 1 ] 表示第二个实参
- arguments 里面有一个属性:callee,属性对应一个函数对象,就是当前正在执行的函数的对象
可以使用 属性 arguments 和函数 fun 做比较,相同返回 true,否则返回 false
console . log( arguments . callee == fun ); // true
例:
function fun(){
console . log( arguments instanceof Array ); // 判断 arguments 是否是数组
console . log( Array . isArray( arguments ) ); // 判断 arguments 是否是数组
console . log( arguments . length ); // fun 函数实参的长度
}
fun( );
arguments的使用的更多相关文章
- js参数arguments的理解
原文地址:js参数arguments的理解 对于函数的参数而言,如下例子 function say(name, msg){ alert(name + 'say' + msg); } say('xiao ...
- javascript arguments(转)
什么是arguments arguments 是是JavaScript里的一个内置对象,它很古怪,也经常被人所忽视,但实际上是很重要的.所有主要的js函数库都利用了arguments对象.所以agru ...
- jQuery之常用且重要方法梳理(target,arguments,slice,substring,data,trigger,Attr)-(一)
1.jquery data(name) data() 方法向被选元素附加数据,或者从被选元素获取数据. $("#btn1").click(function(){ $(" ...
- ORA-00600: internal error code, arguments: [4194]
使用PlateSpin复制出来的一数据库服务器(Oracle 10g)在启动数据库实例时遇到"ORA-00600: internal error code, arguments: [4194 ...
- Javascript——arguments的shift问题谈方法“借用”
今天本来运行了打算这样的方法 arguments.shift() (shift方法是删除数组的第一个元素,例如var arr=[1,2,3,4,5]执行var a=arr.shift();之后,a的值 ...
- format not a string literal and no format arguments
今天cocos2d-x打包 android的时候报错:format not a string literal and no format arguments 报错点是:__String::create ...
- 安装PHP sphinx扩展 sphinx-1.1.0/sphinx.c:105:2: error: too few arguments 错误
表现: /home/sphinx-1.1.0/sphinx.c: In function 'php_sphinx_client_read_property':/home/sphinx-1.1.0/sp ...
- js储存参数的数组arguments
js函数中有个储存参数的数组arguments ,所有函数获得的参数会被编译器挨个保存到这个数组中.于是我们的js版支持参数默认值的函数可以通过另外一种变通的方法实现 function simue ( ...
- Qt - 错误总结 - QObject::connect: Cannot queue arguments of type 'PVCI_CAN_OBJ' (Make sure 'PVCI_CAN_OBJ' is registered using qRegisterMetaType().)
背景:一个线程通过signal-slot发送PVCI_CAN_OBJ类型的值到主线程中, 错误提示: QObject::connect: Cannot queue arguments of type ...
- ORA-00600: internal error code, arguments: [SKGMFAIL], [2], [4], [4], [1], [], [], [], [], [], [], [
ORA-00600: internal error code, arguments: [SKGMFAIL], [2], [4], [4], [1], [], [], [], [], [], [], [ ...
随机推荐
- 马士兵对话京东T6阿里P7(薪水):月薪5万,他为何要离职?
马士兵大佬你知道吗? 你竟然不知道?你怎么可能不知道!你不知道是不可能的! 记得自己的第一行Java代码,你的Hello World是跟着谁学的吗?我的就是马士兵老师! 马士兵是唯一一个在当时讲课是让 ...
- Python【外】第一节 map()和匿名函数的配合使用
Python[外]第一节 map()和匿名函数的配合使用 map()函数 map函数使用语法如下:map(fun, iterable, ...) 功能: map() 会根据提供的函数fun对指定序列i ...
- C#5.0 异步编程 Async和Await--异步方法的规范和注意事项
要些异步方法要注意一下几点: 异步方法的返回值有三种: 1.没有任何返回值的void 2.返回一个Task任务的Task,可以获得该异步方法的执行状态 3.返回Task<T> 可以获得异步 ...
- stty - 改变并打印终端行设置
总览 stty [-F device] [--file=device] [SETTING]... stty [-F device] [--file=device] [-a|--all] stty [- ...
- Nodejs去掉/favicon.ico的请求
const http=require("http"); const server=http.createServer(); server.on("request" ...
- qt大小写字符串比较
https://blog.csdn.net/GraceLand525/article/details/48625593 Qt::CaseSensitivity cs = Qt::CaseInsensi ...
- Yii2数据库操作 事务
Yii2 DAO http://blog.csdn.net/hzqghost/article/details/44116039
- python内置模块-random
print(random.randint(1,10)) 生成随机整数,下限必须小于上限print(random.randrange(1,10)) 生成随机整数,参数为([start],stop,[st ...
- thinkphp5.0多条件模糊查询以及多条件查询带分页如何保留参数
1,多条件模糊查询 等于:map[‘id′]=array(‘eq′,100);不等于:map[‘id′]=array(‘eq′,100);不等于:map[‘id’] = array(‘neq’,100 ...
- project的操作说明
project 1 操作的步骤 设定一个起始时间:7月1号 安排好摘要(任务)的先后顺序 一个一个任务的来:A任务,下面有几个分布实现的部门: 设计部门 3个工作日 程序部门 1个工作日.然后配置相互 ...