Итак, я прочитал несколько сообщений в блоге, SO-темы и другие лекции о подклассификации Array в JavaScript. Общий взгляд на эту тему заключается в том, что нет никакого способа создать подкласс с некоторым недостатком.
Попробовав несколько вещей, я придумал это решение для себя:
// This is the constructor of the new class.
function CustomArray() {
    // The "use strict" statement changes the way the "magic" variable
    // "arguments" works and makes code generally safer.
    "use strict";
    // Create an actual array. This way the object will treat numeric
    // properties in the special way it is supposed to.
    var arr = [],
        i;
    // Overwrite the object prototype, so that CustomArray.prototype is
    // in the prototype chain and the object inherits its methods. This does
    // not break the special behaviour of arrays.
    Object.setPrototypeOf(arr, CustomArray.prototype);
    // Take all arguments and push them to the array.
    for (i = 0; i < arguments.length; i++) {
        arr.push(arguments[i]);
    }
    // Return the array with the modified prototype chain. This overwrites
    // the return value of the constructor so that CustomArray() really
    // returns the modified array and not "this".
    return arr;
}
// Make CustomArray inherit from Array.
CustomArray.prototype = Object.create(Array.prototype);
// Define a method for the CustomArray class.
CustomArray.prototype.last = function () {
    return this[this.length - 1];
};
var myArray = new CustomArray("A", "B", 3);
// [ "A", "B", 3 ]
myArray.length;
// 3
myArray.push("C");
// [ "A", "B", 3, "C" ]
myArray.length;
// 4
myArray.last();
// "C"
Мой вопрос: что-то не так с этим кодом? Мне трудно поверить, что я придумал "одно решение" после того, как многие люди искали меня передо мной.
