Skip to content

Instantly share code, notes, and snippets.

@carbide-public
Created August 25, 2017 18:24
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 carbide-public/98ddd6b703267ee39a8b612d10483ae6 to your computer and use it in GitHub Desktop.
Save carbide-public/98ddd6b703267ee39a8b612d10483ae6 to your computer and use it in GitHub Desktop.
untitled
import Immutable from 'seamless-immutable'
console.clear()
var array = Immutable(["totally", "immutable", { hammer: "Can’t Touch This" }]);
try {
array[1] = "I'm going to mutate you!"
} catch (err) {
console.log(err)
console.log('array[1]', array[1]) // "immutable"
}
try {
array[2].hammer = "hm, surely I can mutate this nested object..."
} catch (err) {
console.log(err)
console.log('array[2].hammer', array[2].hammer) // "Can’t Touch This"
}
console.log(JSON.stringify(array)) // '["totally","immutable",{"hammer":"Can’t Touch This"}]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment