Last active
June 19, 2018 23:19
-
-
Save cgradwohl/533bc3b100cceb9b63b98c243bc68f3e to your computer and use it in GitHub Desktop.
Alert Closure
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
const abductionAlert = (city) => { | |
const title = "Greetings Earthlings! The Current Alien Abduction Count in " | |
+ `${city}` + " Is: "; | |
let count = 0; | |
const alertFactory = () => { | |
alert(`${title} ${++count}`); | |
} | |
return alertFactory; | |
} | |
const abductionEventInSF = abductionAlert('San Francisco'); | |
const abductionEventInPA = abductionAlert('Palo Alto'); | |
abductionEventInSF(); // -> count = 1 | |
abductionEventInPA(); // -> count = 1 | |
abductionEventInSF(); // -> count = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment