Last active
October 24, 2017 20:59
-
-
Save Restuta/97d75332d2b298eab79a8849008bce9c to your computer and use it in GitHub Desktop.
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
function main() { | |
const fn1 = a => ({ | |
get: () => a, | |
set: () => {a = 'Good bye!'} | |
}) | |
const a = 'hello' | |
const {get, set} = fn1(a) | |
// get() holds a reference to a mutable variable | |
console.log(get()) | |
// and because this reference can be mutated | |
set() | |
// get() is not a pure function now. | |
console.log(get()) | |
console.log(a) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment