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], [], [], [], [], [], [], [ ...
随机推荐
- 二、检索语句 SELECT、ORDER BY、WHERE
介绍如何使用SELECT语句从表中检索一个或多个数据列 第二章: SELECT语句 SQL语句可以在一行给出,也可以分成许多行,分成多行更容易调试. 多条SQL语句必须以分号 分隔.多数DBMS不 ...
- [English]could, should, would, may 非單只是過去式
助動詞 could, should, would, may 的用法:(第三冊) 標題句:You should stay here. Would you like to order now? Could ...
- expect的模式
expect的模式其实就是对话模式: expect # 期望什么 send # 我给你什么 比如: expect "password: " # 碰到什么了 s ...
- JS基础API
数据类型 number object string null undefined boolean 转换规则是除了undefined null false 0 NAN ''或""&q ...
- 【mysql升级步骤】windows mysql版本升级 ,mysql 5.6 升级到5.7.27
最近博主由于工作原因需要把之前安装好的的mysql 5.6.44版本卸载,然后安装mysql 5.7.*版本. 前提:为什么要升级到5.7版本? 因为博主在5.6版本上执行脚本时候报出异常:to yo ...
- 2019-8-28-WPF-开发
title author date CreateTime categories WPF 开发 lindexi 2019-8-28 11:3:39 +0800 2018-2-13 17:23:3 +08 ...
- koa2 使用 async 、await、promise解决异步的问题
koa代码编写上避免了多层的嵌套异步函数调用 async await来解决异步 - async await 需要依赖于promise 三主角: __函数前面 async, 内部才能await,要想aw ...
- app混合开发 fastlick.js 在ios上 input标签点击 不灵敏 处理
ios11 上有这个问题 而老版本的ios没有 会出现这个的原因是使用fastclick.js点击后input没有获取焦点,所以只需要在fasyclick的源码的这个位置 可以直接在源码内搜索关键字找 ...
- Java虚拟机(一)
一.Java发展历程 Java之父,James Gosling博士 时间 事件 1991年4月 James Gosling博士领导的Green Project启动,java语言前身Oak启动 1995 ...
- linux IPC socket(2)
使用bind来关联地址和套接字 #include <sys/types.h> #include <sys/socket.h> int bind(int sockfd, cons ...