goatandsheep
2018-10-31
If I declare an object using const
, I shouldn’t be able to use push()
, pull()
, shift()
, nor slice()
on it for it to be truly immutable.
If I declare an object using const
, I shouldn’t be able to use push()
, pull()
, shift()
, nor slice()
on it for it to be truly immutable.
Object.freeze
and Object.seal
to do what you want.that’s amazing. Thank you for that!
const
means the binding can’t change, but it doesn’t say anything about the object that is assigned to that binding. That’s just how this feature was defined.
That being said, it may be useful to have a way to declare a variable whose value is automatically immutable. Something like:
ice arr = [1, 2, 3];
Or not, I don’t really know