Skip to content

Instantly share code, notes, and snippets.

@jaiversin
Created April 9, 2012 16:57
Show Gist options
  • Save jaiversin/2344727 to your computer and use it in GitHub Desktop.
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/
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