Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var W3 = new Object();
  2. W3.Registry = {
  3.     _reg: [],
  4.     set: function (id, value) {
  5.         this._reg[id] = value;
  6.     },
  7.     get: function (id) {
  8.         if (typeof(this._reg[id]) !== "undefined") {
  9.             return this._reg[id];
  10.         }
  11.     },
  12.     unset: function (id) {
  13.         if (typeof(this._reg[id]) !== "undefined") {
  14.             this._reg[id] = undefined;
  15.         }
  16.     },
  17.     isset: function (id) {
  18.         return (typeof(this._reg[id]) !== "undefined");
  19.     }
  20. }
  21.  
  22. W3.Custom = new Object();
  23. W3.Custom.Test = new Object();
  24. W3.Custom.Test.sayHi = function(val) {
  25.     if(val) {
  26.         alert("HI: " + val);
  27.     } else {
  28.         alert("HIII");
  29.     }
  30. };
  31.  
  32. var SomeObject = new Object();
  33. // __call();
  34. SomeObject.__noSuchMethod__ = function(method) {
  35.     var a = method.replace('get', '');
  36.  
  37.     if (W3.Registry.isset(a)) {
  38.         return W3.Registry.get(a);
  39.     }
  40. }
  41.  
  42. W3.Registry.set('Asd', W3.Custom.Test);
  43. SomeObject.getAsd().sayHi('Kizano was here :)');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement