super() on class that extends

Caitlin Potter caitpotter88 at gmail.com
Sat Apr 11 02:38:03 UTC 2015


> No engine has implemented subclassing of `Array`, yet: http://kangax.github.io/compat-table/es6/#Array_is_subclassable <http://kangax.github.io/compat-table/es6/#Array_is_subclassable>

https://github.com/v8/v8-git-mirror/blob/master/test/mjsunit/harmony/classes-subclass-arrays.js <https://github.com/v8/v8-git-mirror/blob/master/test/mjsunit/harmony/classes-subclass-arrays.js>

Not staged yet, but it is implemented and is very cool. few small pieces missing still

> On Apr 10, 2015, at 10:29 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
> 
> No engine has implemented subclassing of `Array`, yet: http://kangax.github.io/compat-table/es6/#Array_is_subclassable <http://kangax.github.io/compat-table/es6/#Array_is_subclassable>
> 
> And, as Sebastian mentioned, you can’t transpile it, because it depends on the cooperation of `Array`: it becomes the base constructor and allocates an exotic array instance (with special handling for `length` etc.) whose prototype is `new.target`.
> 
> Axel
> 
> 
>> On 11 Apr 2015, at 03:57, Garrett Smith <dhtmlkitchen at gmail.com <mailto:dhtmlkitchen at gmail.com>> wrote:
>> 
>> On 4/10/15, Axel Rauschmayer <axel at rauschma.de <mailto:axel at rauschma.de>> wrote:
>>> The reason why you need to call the super-constructor from a derived class
>>> constructor is due to where ES6 allocates instances - they are allocated
>>> by/in the base class (this is necessary so that constructors can be
>>> subclassed that have exotic instances, e.g. `Array`):
>>> 
>> Can you please explain how extending Array works. Also what is the
>> optional identifier optional for in ClassExpression:
>> 
>> var myArray = (new class B extends Array {
>>   constructor() {
>>     super(1,2,3,4,5);
>>  }
>> });
>> alert(myArray.length); // it's 0 in Babel.
>> 
>> -- 
>> Garrett
>> @xkit
>> ChordCycles.com <http://chordcycles.com/>
>> garretts.github.io
>> personx.tumblr.com
> 
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de <mailto:axel at rauschma.de>
> rauschma.de
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150410/950962a9/attachment.html>


More information about the es-discuss mailing list