Why Javascript function `arguments` is not an instance of Array in node.js?
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开发者_JS百科(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?
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.
And yes, this is indeed one of the bad parts of JavaScript.
精彩评论