Skip to content

Instantly share code, notes, and snippets.

@postpostscript
Created April 24, 2016 17:06
Show Gist options
  • Save postpostscript/fed2680efc3664b3ad66ba7d03e1da9b to your computer and use it in GitHub Desktop.
Save postpostscript/fed2680efc3664b3ad66ba7d03e1da9b to your computer and use it in GitHub Desktop.
function once(fns, callback, args) {
var c = 0;
var len = fns.length;
var results = [];
fns.forEach(function(fn, i) {
fn.apply(fn, [function(value) {
results[i] = value;
c++;
if (c == len) {
callback.apply(callback, results);
}
}].concat(args));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment