Created
June 22, 2019 04:31
-
-
Save jsmanifest/9d4d248f8a1f097c219887030eeaac0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const massCreateWarriors = function(names) { | |
return (onCreate) => { | |
const warriors = [] | |
names.forEach((name) => { | |
const newWarrior = new Warrior(name) | |
if (onCreate) onCreate(newWarrior) | |
warriors.push(newWarrior) | |
}) | |
return warriors | |
} | |
} | |
const prepareWarriors = massCreateWarriors(['bob', 'joe', 'sally', 'woodie']) | |
const newWarriors = prepareWarriors(function onCreate(newWarrior) { | |
if (newWarrior.name === 'sally') { | |
newWarrior.theme = 'red' | |
} | |
characters.push(newWarrior) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment