super keyword can call the parent version of the method
classLogger {log() {console.log("Log to console..."); }}classExtLoggerextendsLogger {log() {super.log(); // from Loggerconsole.log("process..."); }}constlogger=newExtLogger();logger.log();// Log to console...// process...
Getters & setters
Getters and setters work in the same way as in objects. They are essentially functions that execute on getting and setting a value, but look like regular properties to an external code.
Static methods/properties are called without creating an instance of their class.
classCalc {static pi =3.14;staticsum(a, b) {return a + b; }avg(a, b) {// "this" is not available!returnCalc.sum(a, b) /2; }}console.log(Calc.pi); // 3.14Calc.sum(20,30); // 50
Static properties/methods are not available for instances.
Mixin is just objects. They are used to add additional properties/methods to existing classes. The mixins themselves are not used.
classSquare {constructor(size) {this.size = size; }}constareaMixin= {area() {console.log(Math.pow(this.size,2)); },};// Copying methods from a mixin to a classObject.assign(Square.prototype, areaMixin);constbox=newSquare(5);box.area(); // 25