为什么Javascript函数`arguments`不是node.js中的Array实例? [英] Why Javascript function `arguments` is not an instance of Array in node.js?

查看:74
本文介绍了为什么Javascript函数`arguments`不是node.js中的Array实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近查看了很多NodeJS和Javascript代码,似乎参数不是Array的一个实例,但仍然表现得像一个,所以人们会像 Array.prototype.slice.call(arguments, ...) []。slice.call(arguments)这增加了详细程度并增加了新手理解的障碍等等。有没有为什么参数不是Array的一个实例,或者这只是那些坏的部分?

Looking at a lot of NodeJS and Javascript code recently, it seems arguments is not an instance of Array but still behaves like one, so people do stuff like Array.prototype.slice.call(arguments, ...) or [].slice.call(arguments) which adds verbosity and increases hurdle for newbies to understand etc.. Is there a reason why arguments isnt an instance of Array or is this just one those bad parts?

推荐答案

arguments 是一个独立的对象,恰好有一个 length 属性,并且能够使用 [] 将其编入索引。但除此之外,它只是一个对象,而不是 Array 对象。

NO. arguments is a standalone object that just so happens to have a length property and the ability to use [] to index it. But otherwise, it is just an object, not an Array object.

是的,这确实是其中之一JavaScript的不良部分。

And yes, this is indeed one of the bad parts of JavaScript.

这篇关于为什么Javascript函数`arguments`不是node.js中的Array实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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