8. super in Objects
ES6 allows to use super
method in (classless) objects with prototypes. Following is a simple example:
const parent = {
foo() {
console.log("Hello from the Parent");
}
}
const child = {
foo() {
super.foo();
console.log("Hello from the Child");
}
}
Object.setPrototypeOf(child, parent);
child.foo(); // Hello from the Parent
// Hello from the Child