9 ms·
What if you just did var x = { ...}; var y = Object.create(x); Object.freeze(y); Object.preventExtension(y); Wouldn't that achieve the same effect?
by CountHackulus 13y ago
What if you just did
var x = { ...};
var y = Object.create(x);
Object.freeze(y);
Object.preventExtension(y);
Wouldn't that achieve the same effect?
- deleted 13y ago[deleted]
- bolshchikov 13y agoNo, you can still mutate the array and it will influence the original model. http://jsbin.com/IvIXUZO/1/edit http://jsbin.com/IvIXUZO/1/edit
- krebby 13y agoso just deep-clone your object before freezing / sealing, right?
- Sharlin 13y agoNo need to freeze/seal if you deep-clone; it's not your business what the recipient does with its own copy. The point is, copying can be expensive. In C++, you can pass by copy, by reference, or by const reference. The idea is that a const reference means that the object is not modifiable through that reference, no matter whether it's itself const or not.
- krebby 13y agoso just deep-clone your object before freezing / sealing, right?