8. 对象超类

ES6 允许在对象中使用 super 方法:

  1. var parent = {
  2. foo() {
  3. console.log("Hello from the Parent");
  4. }
  5. }
  6. var 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