为什么数组转换成片的JavaScript参数数组 [英] why does array slice convert javascript arguments to array
问题描述
为什么采用切片方法的JavaScript 参数
值如下: Array.prototype.slice.call(参数)
将其转换为一个数组?如果片上使用数组和参数
不是数组,那么如何工作的呢?它是一种特殊情况下,当片
适用于依据?
Why does applying the slice method to the javascript arguments
value as follows Array.prototype.slice.call(arguments)
convert it to an array? If slice is used on arrays, and arguments
is not an array, then how does this work? Is it just a special case when slice
is applied to arguments?
推荐答案
从 ECMAScript规范> Array.prototype.slice :
的注意的的片
功能是有意通用的;它不要求其这个
值是一个数组对象。因此它可以被转移到其他类型的对象,其用作方法。无论是片
功能可以成功地应用到主机对象是依赖于实现的。
NOTE The
slice
function is intentionally generic; it does not require that itsthis
value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether theslice
function can be applied successfully to a host object is implementation-dependent.
因此,片
的作品,有一个长度
属性(如对每个对象参数
对象)。即使对于那些不这样做,就那么就返回一个空数组。
And so, slice
works on every object that has a length
property (like Arguments
objects). And even for those that do not, it then just returns an empty array.
这篇关于为什么数组转换成片的JavaScript参数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!