Created
April 24, 2016 17:06
-
-
Save postpostscript/fed2680efc3664b3ad66ba7d03e1da9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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