Created
April 9, 2012 16:57
-
-
Save jaiversin/2344727 to your computer and use it in GitHub Desktop.
Creates a queue (poor queue impl, i know) and add function metadata info for further callings. Improved version by @simevidas http://jsfiddle.net/CEdPS/3/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Queue(arr) { | |
var i = 0; | |
this.callNext = function() { | |
typeof arr[i].f == 'function' && arr[i].f(arr[i++].params); | |
}; | |
} | |
function f1(params) { | |
alert(params[0]); | |
} | |
function f2(params) { | |
alert(2); | |
} | |
function f3(params) { | |
alert(3); | |
} | |
var queue = new Queue([{ | |
f: f1, | |
params: ["Some param"]}, | |
{ | |
f: f2, | |
params: ["doesn't matter"]}, | |
{ | |
f: f3, | |
params: ["doesn't matter"]}]); | |
queue.callNext(); | |
queue.callNext(); | |
queue.callNext(); | |
queue.callNext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment