Class extending function/generator/class literals
# Rick Waldron (11 years ago)
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: people.mozilla.org/~jorendorff/es6-draft.html#sec-static-semantics-constructormethod , people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-classdefinitionevaluation. This is all further detailed here: people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-objects, specifically: 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
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?
This question came from the fact that classes can be stored in variables like so: