Skip to content

Instantly share code, notes, and snippets.

@bradcypert
Last active June 29, 2018 17:30
Show Gist options
  • Save bradcypert/1487efc0277aca13236c15bd78cf6ce7 to your computer and use it in GitHub Desktop.
Save bradcypert/1487efc0277aca13236c15bd78cf6ce7 to your computer and use it in GitHub Desktop.
function when(constraints) {
for(obj of constraints) {
var ths = obj['this'];
var d = obj['do'];
if (ths && typeof ths === "function" && d && typeof d === "function") {
var response = ths();
if (response === true) return d()
}
}
}
when([
{this: function() {return true}, do: function() {console.log("woo")}},
{this: function() {return false}, do: function() {console.log("oh no")}}
])
let resp = when([
{this: () => true, do: () => 1234}
])
console.log(resp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment