Search code examples
javascriptnode.jsv8

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(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?


Solution

  • 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.