Class extending function/generator/class literals

Rick Waldron waldron.rick at gmail.com
Sun Aug 24 15:03:04 PDT 2014


On Sun, Aug 24, 2014 at 3:22 PM, Isiah Meadows <impinball at gmail.com> wrote:

> I know this wouldn't be a common use case, but might come into play with
> minifiers later on. Would any of the following be potentially valid in ES6?
>
>     class Foo extends function() {} { /* class body */ }
>

This is valid:

  class F extends function () { this.prop = 1; } {
    constructor() {
      super();
    }
  }

  var f = new F();
  console.log(f.prop === 1); //  true



>      class Foo extends function* (bar) { yield bar } { /* class body */ }
>

This won't work correctly: the constructor method of Foo can't be a
generator method:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-static-semantics-constructormethod
,
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-classdefinitionevaluation.
This is all further detailed here:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-objects,
specifically:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-constructor


>     class Foo extends class { /* super body */ } { /* class body */ }
>

This is valid:

  class C extends class { get() { return 1; } } {
    constructor() {
      super();
    }
  }

  var c = new C();

  console.log(c.get() === 1); // true



Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140824/a8157782/attachment.html>


More information about the es-discuss mailing list