Skip to content

Instantly share code, notes, and snippets.

@bellentuck
Created February 5, 2018 22:03
Show Gist options
  • Save bellentuck/0a37298809690bdfa09258bb6267bf4c to your computer and use it in GitHub Desktop.
Save bellentuck/0a37298809690bdfa09258bb6267bf4c to your computer and use it in GitHub Desktop.
calling all args! xoxo, generator
function* cycleThruFnArgs(obj, fnArr) {
while (fnArr.length > 0) {
yield fnArr.shift().call(obj);
}
}
function callAll(obj, args) {
if (arguments.length < 2) throw 'Supply obj and args array';
var gen = cycleThruFnArgs(obj, args);
var next;
var result = [];
do {
next = gen.next().value;
result.push(next);
} while (next);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment