Guest User

Untitled

a guest
Sep 3rd, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Class_Bar()
  2. {
  3.     this.panel = null;
  4.  
  5.     this.init = function ()
  6.     {
  7.         // do some stuff
  8.         this.panel = 20;
  9.     }
  10.    
  11.     this.apply = function ()
  12.     {
  13.         alert(Bar == this);
  14.         Bar.x();
  15.         this.x();
  16.     }
  17.    
  18.     this.x = function()
  19.     {
  20.         alert("Some friendly message");
  21.         alert(Bar.panel);
  22.     }
  23. }
  24.  
  25. var Bar = new Class_Bar();
  26.  
  27. function Class_Factory()
  28. {
  29.     this.factories = new Array();
  30.    
  31.     this.add = function (init, apply)
  32.     {
  33.         this.factories.push({"init":init, "apply":apply});
  34.     }
  35.    
  36.     this.init = function ()
  37.     {
  38.         for (var i = 0; i < this.factories.length; ++i)
  39.         {
  40.             this.factories[i]["init"]();
  41.         }
  42.     }
  43.  
  44.     this.apply = function ()
  45.     {
  46.         for (var i = 0; i < this.factories.length; ++i)
  47.         {
  48.             this.factories[i]["apply"]();
  49.         }
  50.     }
  51. }
  52.  
  53. var Factory = new Class_Factory();
  54.  
  55. function main()
  56. {
  57.     // Case 1
  58.     Factory.add(Bar.init, Bar.apply);
  59.    
  60.     Factory.init();
  61.     Factory.apply();
  62.  
  63.     // Case 2
  64.     Bar.init();
  65.     Bar.apply();
  66. }
  67.  
  68. main();
Advertisement
Add Comment
Please, Sign In to add comment