Last active
September 23, 2019 13:12
-
-
Save jbmilgrom/204234a1f7faf5be38d2e30ddafb44bc to your computer and use it in GitHub Desktop.
Problems with "internal" mutability
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 buildCallbacks = items => { | |
const callbacks = []; | |
let i; | |
for (i = 0; i < items.length; i++) { | |
callbacks.push(() => items[i]); | |
} | |
return callbacks; | |
} | |
const callbacks = buildCallbacks(["hello", "cruel", "world"]); | |
callbacks.length; // => 3 | |
callbacks[0](); // => undefined | |
callbacks[1](); // => undefined | |
callbacks[2](); // => undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment