Subclassing an array and array methods
Axel Rauschmayer
axel at rauschma.de
Fri Nov 11 09:47:20 PST 2011
> function createArraySubclass(proto,...values) {
> return proto <| [...values].{
> [Array.derivedArrayKey](){return proto<| [ ]}
> }
> }
I’m curious: Why wouldn’t one extend Array, instead?
function SubArray() {
}
SubArray.prototype = Object.create(Array.prototype);
SubArray.prototype.pushAll = function() {
Array.prototype.push.apply(this, arguments);
return this;
}
var s = new SubArray().pushAll(3,4,5);
--
Dr. Axel Rauschmayer
axel at rauschma.de
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
More information about the es-discuss
mailing list