Advertisement
JordanScripter1337

Inheritance (Javascript Version)

Sep 19th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var module, moduleKeywords,
  2.   indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  3.  
  4. moduleKeywords = ['extended,included'];
  5.  
  6. module = (function() {
  7.   function module() {}
  8.  
  9.   module.extend = function(obj) {
  10.     var key, ref, value;
  11.     for (key in obj) {
  12.       value = obj[key];
  13.       if (indexOf.call(moduleKeywords, key) < 0) {
  14.         this[key] = value;
  15.       }
  16.     }
  17.     if ((ref = obj.extended) != null) {
  18.       ref.apply(this);
  19.     }
  20.     return this;
  21.   };
  22.  
  23.   module.include = function(obj) {
  24.     var key, ref, value;
  25.     for (key in obj) {
  26.       value = obj[key];
  27.       if (indexOf.call(moduleKeywords, key) < 0) {
  28.         this.prototype[key] = value;
  29.       }
  30.     }
  31.     if ((ref = obj.included) != null) {
  32.       ref.apply(this);
  33.     }
  34.     return this;
  35.   };
  36.  
  37.   return module;
  38.  
  39. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement