Created
February 14, 2017 12:57
-
-
Save deepak/036f048502449baae7ee0fbaa4789160 to your computer and use it in GitHub Desktop.
use currying
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
let MODIFY = "MODIFY"; | |
let ADD = "ADD"; | |
let DELETE = "DELETE"; | |
function checkAction(actions, recon, action, cb) { | |
if (actions.indexOf(action) > -1) { | |
cb(recon); | |
} | |
} | |
function buildRecon() { | |
let actions = [ | |
MODIFY, | |
// ADD, | |
DELETE | |
]; | |
let reconActions = []; | |
let factory = checkAction.bind(null, actions, reconActions); | |
factory(MODIFY, (arr) => { arr.push(`pushed ${MODIFY}`); }); | |
factory(ADD, (arr) => { arr.push(`pushed ${ADD}`); }); | |
factory(DELETE, (arr) => { arr.push(`pushed ${DELETE}`); }); | |
return reconActions; | |
} | |
let reconActions = buildRecon(); | |
console.dir(reconActions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment