Skip to content

Instantly share code, notes, and snippets.

@karolk
Last active December 12, 2015 04:38
Show Gist options
  • Save karolk/4715684 to your computer and use it in GitHub Desktop.
Save karolk/4715684 to your computer and use it in GitHub Desktop.
Problems with state
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);
}
}
}
@timruffles
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment