3 ms·
They also add class-side inheritance. This allows the constructor to inherit its properties from a parent constructor: class Class {} Class.hello = "h
by wycats 14y ago
They also add class-side inheritance.
This allows the constructor to inherit its properties from a parent constructor:
class Class {}
Class.hello = "hello";
class SubClass extends Class {}
SubClass.hello // "hello"
This doesn't add any new semantics on top of the already-approved `__proto__` (which already exists in all browsers but IE):
Class = function() {};
Class.hello = "hello";
SubClass = function() {};
SubClass.__proto__ = Class;
SubClass.hello // "hello"
EDIT: Oh, and they add `super`:
class Speaker {
say(string) { console.log(string); }
}
class Yeller extends Speaker {
say(string) { super(string.toUpperCase()); }
}
new Yeller().say("hi") // "HI"
- gsnedders 14y agoAh, I'd forgotten it now mutated [[Prototype]] and not the prototype property's [[Prototype]] (IIRC, earlier drafts had it mutating the latter, i.e., `SubClass.prototype.__proto__`). `super` is indeed new semantics though, so that is definitely true.
- delaaxe 14y agoAbout the last example, I think you meant : super.say(string.toUpperCase()); See: http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes http://wiki.ecmascript.org/doku.php?id=strawman:maximally_mi...