为什么数组转换成片的JavaScript参数数组 [英] why does array slice convert javascript arguments to array

查看:139
本文介绍了为什么数组转换成片的JavaScript参数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么采用切片方法的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 its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the slice 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆