Array.prototype.slice.apply(arguments, [1])
来源:互联网 发布:虚拟机 ubuntu nat 编辑:程序博客网 时间:2024/06/13 07:49
arguments参数
生成
JavaScript在创建函数时,会自动生成一个Arguments对象实例arguments,可以用数组下标的方式”[]”引用arguments的元素。arguments.length为函数实参个数,arguments.callee引用函数自身。特性:
arguments对象和Function是分不开的。因为arguments这个对象不能显式创建,arguments对象只有函数开始时才可用。
使用方法:
虽然arguments对象并不是一个数组,但是访问单个参数的方式与访问数组元素的方式相同
Array.prototype.slice.apply(arguments)用意
直接调用arguments.slice()将返回一个”Object doesn’t support this property or method”错误,因为arguments不是一个真正的数组。调用Array.prototype.slice.apply(arguments)的意义就在于它能将函数的参数对象转化为一个真正的数组。
Array.prototype.slice.apply(arguments, [1])用意
首先这段代码的目的是为了拿到参数里除第一个以外后面的所有参数。
现在arguments 不是数组,所以不能直接调用slice方法,在JavaScript 中借用其它对象的方法可以通过apply或者call,以call为例,上述例子应该改写为:
// 需要借用的方法slice在Array.prototype 上,然后call接受两个参数,第一个是需要借用方法的对象,第二个是传进方法的参数,也就是1Array.prototype.slice.call(arguments, 1)// 也可以写成[].slice.call(arguments, 1)
apply方法与call方法是一样的,区别只是传参的形式,需要把方法参数按数组形式传进:
Array.prototype.apply(arguments, [1])
阅读全文
0 0
- Array.prototype.slice.apply(arguments, [1])
- js--Array.prototype.slice.apply(arguments);
- 理解 JavaScript 中的 Array.prototype.slice.apply(arguments)
- Array.prototype.slice.call(arguments, 1)
- Array.prototype.slice.call(arguments,1)原理
- Array.prototype.slice.call(arguments,1)原理
- Array.prototype.slice.call(arguments,1)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- HTTP 1.1与HTTP 1.0的比较
- 02 JXV相关功能展示
- 分布式系统事务一致性解决方案
- Android 开源项目2017总结
- R连接Mysql
- Array.prototype.slice.apply(arguments, [1])
- 10.31作业
- linux查看外网ip
- CSDN博客排名前15名
- Smartctl – Monitoring and Analysis tool for Hard drive
- UE使用技巧总结
- 索引失效原因总结
- IOS之xcode的常用操作
- (HDOJ)2044——一只小蜜蜂...(递推)