8. super in Objects

ES6 allows to use super method in (classless) objects with prototypes. Following is a simple example:

  1. const parent = {
  2. foo() {
  3. console.log("Hello from the Parent");
  4. }
  5. }
  6. const child = {
  7. foo() {
  8. super.foo();
  9. console.log("Hello from the Child");
  10. }
  11. }
  12. Object.setPrototypeOf(child, parent);
  13. child.foo(); // Hello from the Parent
  14. // Hello from the Child