2 ms·
As I said, I simplified the expression to show all the relevant parts of the pattern in a single function. In a real application, either all the features of th
by IsaacSchlueter 17y ago
As I said, I simplified the expression to show all the relevant parts of the pattern in a single function. In a real application, either all the features of the pattern might be inline, or some might be delegated to other functions, or some might be omitted.
Also, you can make it slightly more powerful by wrapping an object around it. I did this recently:
var queue = (function () {
var q = [];
return {
run : function run () {
var fn = q.shift();
if (fn) setTimeout(function () {
fn();
run();
}, 0);
return this;
},
push : function (fn) {
q.push(fn);
return this;
}
};
})();
so you can do stuff like this:
queue.push(
function () {...}
).push(
function(){...}
).start();