Skip to content

Instantly share code, notes, and snippets.

@Restuta
Last active October 24, 2017 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Restuta/97d75332d2b298eab79a8849008bce9c to your computer and use it in GitHub Desktop.
Save Restuta/97d75332d2b298eab79a8849008bce9c to your computer and use it in GitHub Desktop.
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