Allen Wirfs-Brock (2015-01-16T20:02:57.000Z)
On Jan 16, 2015, at 11:40 AM, Kevin Smith wrote:

> Changes include: Updated specification to use and support the new built-in subclassing scheme described at: https://github.com/tc39/ecma262/blob/master/workingdocs/ES6-super-construct%3Dproposal.md
> 
> This looks nice.  An interesting question:
> 
> For classes that have divergent [[Construct]]/[[Call]] behavior, should the [[Call]] behavior be "inherited" by derived classes?
> 
>     class MyDate extends Date {}
>     console.log(MyDate(1, 2, 3));  A string, or throw an error?
> 
> 

Since the above class definition does not include an explicit constructor body, it gets the equivalent of
   constructor(...args) {super(...args)}
as its implicit constructor definition

A 'super()' call throws if the NewTarget is null (ie, if the constructor is invoked via [[Call]] )

If you want to inherit call behavior you need to code it as:

  class MyDate extends Date {
     constructor(...args) {
         if (new.target===null) return super.constructor(...args)
         super(...args);
      }
}

That's assuming 'new.target' makes it into ES6.  Without it you would have to do something like:

  class MyDate extends Date {
     constructor(...args) {
         let calledAsFunction=true;
         try {
              let thisValue = this;  //can't reference 'this' prior to 'super()' in a [[Construct]] call of a derived function
         } catch (e} {
            let calledAsFunction = false
        }
        if (calledAsFunction) return super.constructor(...args)
        super(...args);
      }
}

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150116/f8605b1a/attachment.html>
d at domenic.me (2015-01-28T19:26:58.792Z)
Since the above class definition does not include an explicit constructor body, it gets the equivalent of

    constructor(...args) {super(...args)}

as its implicit constructor definition

A 'super()' call throws if the NewTarget is null (ie, if the constructor is invoked via [[Call]] )

If you want to inherit call behavior you need to code it as:

```js
class MyDate extends Date {
    constructor(...args) {
        if (new.target===null) return super.constructor(...args)
        super(...args);
    }
}
```

That's assuming 'new.target' makes it into ES6.  Without it you would have to do something like:

```js
class MyDate extends Date {
    constructor(...args) {
        let calledAsFunction=true;
        try {
            let thisValue = this;  //can't reference 'this' prior to 'super()' in a [[Construct]] call of a derived function
        } catch (e} {
            let calledAsFunction = false
        }
        if (calledAsFunction) return super.constructor(...args)
        super(...args);
    }
}
```