Last active
December 12, 2015 04:38
-
-
Save karolk/4715684 to your computer and use it in GitHub Desktop.
Problems with state
This file contains hidden or 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 Closure(args) { | |
var refState = args[0] //some state by referencing | |
//completely new state | |
var newState = { | |
order: 1 | |
} | |
//when objects are passed around they might end up cached elsewhere | |
doSomethingWithState(refState, newSate) | |
//getting rid of cached state is not really possible | |
refState = null; | |
//let's assume we forget to do this | |
//newState = null; | |
//this will have references to some state | |
return function() { | |
if (newState) { | |
alert(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sure - the nice thing about values vs a mutable object is that once you have a reference to it, you know it'll stay that way. there's no way you'll check it again and it'll have an invalid value etc