r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

3

u/[deleted] May 29 '19

But even Object.freeze won't freeze deeply - i.e,

const obj1 = {
  obj2: {
    foo: "bar"
  }
}
Object.freeze(obj1);
obj1.obj2 = {foo: 'baz'} // noop 
console.log(JSON.stringify(obj1)) // -> {"obj2":{"foo":"bar"}}
obj1.obj2.foo = 'baz' // legal.
console.log(JSON.stringify(obj1)) // -> {"obj2":{"foo":"baz"}}

This is why the Immutable.js library is a thing.

1

u/starm4nn May 29 '19

Doesn't freeze mean performance loss?