Advertisement
fruffl

Need Help

Dec 15th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             __queue__ : function(runonce)
  2.             {
  3.                 var __queue = new Array();
  4.                 var __runonce = ((runonce !== true) ? false : true);
  5.                 alert(runonce + ' -> ' +  __runonce);
  6.                
  7.                 this.push = function(fn)
  8.                 {
  9.                     __queue.push(fn);
  10.                     return this;
  11.                 }
  12.                
  13.                 this.execute = function()
  14.                 {
  15.                     alert('run once? ' +  __runonce);
  16.                     if(__queue.length === 0)
  17.                     {
  18.                         alert('No queue');
  19.                         return this;
  20.                     }
  21.                    
  22.                     var q = __queue;
  23.                     while(q.length > 0)
  24.                         (q.shift())();
  25.                        
  26.                     if(__runonce === true)
  27.                         this.reset();
  28.                        
  29.                     return this;
  30.                 }
  31.                
  32.                 this.reset = function()
  33.                 {
  34.                     __queue = new Array();
  35.                     return this;
  36.                 }
  37.             },
  38. ...
  39.  
  40.  
  41.  
  42.         // Test script:
  43.         var test21 = function(){alert('test2.1')};
  44.         var test22 = function(){alert('test2.2')};
  45.         var bar = new $.xtcmApp.global.__class__.__queue__(true);
  46.         bar.push(test21).push(test22);
  47.  
  48.  
  49.         // expected:
  50.         bar
  51.         .execute() // test21 and test22
  52.         .execute() // test21 and test22
  53.  
  54.         // actual:
  55.         bar
  56.         .execute() // test21 and test22
  57.         .execute() // No queue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement