Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 22, 2019 04:31
Show Gist options
  • Save jsmanifest/9d4d248f8a1f097c219887030eeaac0a to your computer and use it in GitHub Desktop.
Save jsmanifest/9d4d248f8a1f097c219887030eeaac0a to your computer and use it in GitHub Desktop.
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