Skip to content

Instantly share code, notes, and snippets.

@oxUnd
Last active August 29, 2015 13:56
Show Gist options
  • Save oxUnd/9200485 to your computer and use it in GitHub Desktop.
Save oxUnd/9200485 to your computer and use it in GitHub Desktop.
var queue = function(funcs, scope) { 
    (function next() { 
          if(funcs.length > 0) { 
              funcs.shift().apply(scope || {}, [next].concat(Array.prototype.slice.call(arguments, 0))); 
          } 
    })(); 
}; 
 
var obj = { 
    value: null 
}; 
 
queue([ 
    function(callback) { 
        var self = this; 
        setTimeout(function() { 
            self.value = 10; 
            callback(20); 
        }, 200); 
    }, 
    function(callback, add) { 
        console.log(this.value + add); 
        callback(); 
    }, 
    function() { 
        console.log(obj.value); 
    } 
], obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment