如何将函数的实际参数转换成数组
实际参数在函数中我们可以使用 arguments 对象获得 (注:形参可通过 arguments.callee 获得),虽然 arguments 对象与数组形似,但仍不是真正意义上的数组。 值得庆幸的是,我们可以通过数组的 slice 方法将 arguments 对象转换成真正的数组: var args = Array.prototype.slice.call(arguments, 0); 对于slice 方法,ECMAScript 262 中 15.4.4.10 Array.prototype.slice (start, end) 章节有备注: The slice function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects [...]
... 25 条评论 »
