Advertisement
kstoyanov

10. Extensible Class

Sep 25th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function extensibleClass() {
  2.   let id = 0;
  3.   return class Extensible {
  4.     constructor() {
  5.       this.id = id++;
  6.     }
  7.  
  8.     extend(template) {
  9.       Object.entries(template)
  10.         .forEach(([key, value]) => {
  11.           if (typeof value === 'function') {
  12.             Object.getPrototypeOf(this)[key] = value;
  13.           } else {
  14.             this[key] = value;
  15.           }
  16.         });
  17.     }
  18.   };
  19. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement