Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __queue__ : function(runonce)
- {
- var __queue = new Array();
- var __runonce = ((runonce !== true) ? false : true);
- alert(runonce + ' -> ' + __runonce);
- this.push = function(fn)
- {
- __queue.push(fn);
- return this;
- }
- this.execute = function()
- {
- alert('run once? ' + __runonce);
- if(__queue.length === 0)
- {
- alert('No queue');
- return this;
- }
- var q = __queue;
- while(q.length > 0)
- (q.shift())();
- if(__runonce === true)
- this.reset();
- return this;
- }
- this.reset = function()
- {
- __queue = new Array();
- return this;
- }
- },
- ...
- // Test script:
- var test21 = function(){alert('test2.1')};
- var test22 = function(){alert('test2.2')};
- var bar = new $.xtcmApp.global.__class__.__queue__(true);
- bar.push(test21).push(test22);
- // expected:
- bar
- .execute() // test21 and test22
- .execute() // test21 and test22
- // actual:
- bar
- .execute() // test21 and test22
- .execute() // No queue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement