tests to compare different methods of sub-prototyping Array
Switch branches/tags
Nothing to show
Failed to load latest commit information.



I put this together to test out some of the advice provided in this excellent article: http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/

I wanted to see how much of this was still true, several years on. This advice was also provided mostly for web browsers, and I wanted to see how Node.JS affected the outcomes.

Getting Started

You'll need the CLI module for grunt installed globally:

npm install -g grunt-cli

In the project root, run:

npm install

That will install the npm modules required for running the unit tests.

Once that's done, you can run the Node.JS unit tests with:



grunt test

Additionally, you may run the browser-based tests with:

grunt browser

although these tests are more interesting if actually opened in real browsers. In fact, the PhantomJS + Mocha combination for these browser tests doesn't really work that well in Node.JS, so grab a browser.



  • grunt test with Node.JS v0.10.5

  • tests confirm Array-detectability, if manipulating length effects indices as expected, and if manipulating indices effects length as expected

              | proper [[Class]] | length > indices | indices > length

--------------- | ---------------- | ---------------- | ----------- naive | no | yes | no stack | no | yes | no makeSubArray | no | yes | yes wrapper: direct | yes | yes | yes

This is quite different to @kangax's original results. I can only guess that V8 does things differently compared to the browser JavaScript engines that were used in the original comparision.

Google Chrome

  • browser tests run in Chromium 26

  • same results as Node.JS

It isn't surprising the Chrome repeats the Node.JS results, as they both use V8.

Mozilla Firefox

  • browser tests run in Firefox 20

  • same results as Node.JS

Firefox's JavaScript engine is a modern ECMAScript 5.1 engine, just like V8. I'm starting to sense a pattern here.

Internet Explorer

  • browser tests run in Microsoft Internet Explorer 10

  • same results as the others


Copyright (c) 2013 Ron Waldon
Licensed under the MIT license.