Skip to content

Instantly share code, notes, and snippets.

@kwoktung
Created March 1, 2020 06:58
Show Gist options
  • Save kwoktung/41ee0eecb05383fa127201a8a840655e to your computer and use it in GitHub Desktop.
Save kwoktung/41ee0eecb05383fa127201a8a840655e to your computer and use it in GitHub Desktop.
function executeQueue(...fns) {
fns = fns.reverse()
return fns.reduce(function(next, fn) {
return fn.bind(this, next)
}, function() {
console.log("DONE")
})
}
/*
function executeQueue(...fns) {
let next = function(){ console.log("DONE"); }
let i = fns.length - 1;
while(i >= 0) {
next = fns[i].bind(this, next);
i -= 1;
}
return next
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment