super() on class that extends

Sébastien Cevey seb.cevey at
Sat Apr 11 13:09:31 UTC 2015

Does the same apply to subclassing Error?

I've been trying to do that but it doesn't seem to work as expected, in
particular passing the message as argument to `super` doesn't seem to do

For example:

``` javascript
class Foo extends Error {
  constructor(message) {

var err1 = new Foo("arg");
console.log(err1); // plain Foo object
console.log(err1.message); // "" (empty string!?)

var err2 = new Error("arg");
console.log(err2); // Error object
console.log(err2.message); // "arg"

The above is true both with Traceur and Babel.!%3F)%0A%0Avar%20err2%20%3D%20new%20Error(%22arg%22)%3B%0Aconsole.log(err2)%3B%20%2F%2F%20Error%20object%0Aconsole.log(err2.message)%3B%20%2F%2F%20%22arg%22!%3F)%0A%0Avar%20err2%20%3D%20new%20Error(%22arg%22)%3B%0Aconsole.log(err2)%3B%20%2F%2F%20Error%20object%0Aconsole.log(err2.message)%3B%20%2F%2F%20%22arg%22

On Sat, 11 Apr 2015 at 03:30 Axel Rauschmayer <axel at> wrote:

> No engine has implemented subclassing of `Array`, yet:
> 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 ``.
> Axel
> On 11 Apr 2015, at 03:57, Garrett Smith <dhtmlkitchen at> wrote:
> On 4/10/15, Axel Rauschmayer <axel at> 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
> --
> Dr. Axel Rauschmayer
> axel at
> _______________________________________________
> es-discuss mailing list
> es-discuss at


Visit On your mobile and tablet, download the Guardian 
iPhone and Android apps and our tablet editions  Save up to 57% by subscribing to the Guardian 
and Observer - choose the papers you want and get full digital access. 

This e-mail and all attachments are confidential and may also be 
privileged. If you are not the named recipient, please notify the sender 
and delete the e-mail and all attachments immediately. Do not disclose the 
contents to another person. You may not use the information for any 
purpose, or store, or copy, it in any way.  Guardian News & Media Limited 
is not liable for any computer viruses or other material transmitted with 
or as part of this e-mail. You should employ virus checking software.
Guardian News & Media Limited is a member of Guardian Media Group plc. Registered 
Office: PO Box 68164, Kings Place, 90 York Way, London, N1P 2AP.  Registered 
in England Number 908396

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list