Created
February 5, 2018 22:03
-
-
Save bellentuck/0a37298809690bdfa09258bb6267bf4c to your computer and use it in GitHub Desktop.
calling all args! xoxo, generator
This file contains 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* 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