Advertisement
Lulunga

Classes 05. Extensible Class IIFE

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