Use Object.freeze in a backwards compatible way

This commit is contained in:
Jason 2016-04-04 19:02:20 -05:00
parent 7452fe0c0b
commit 8b79d0f94b

View File

@ -541,7 +541,10 @@ function equal(a, b) {
function defineReadonlyProperty(obj, key, value) {
var copy = deepCopy(value);
Object.freeze(copy);
// In ES6, freezing a literal is OK (it returns the same value), but in previous versions it's an exception.
if (typeof copy == "object") {
Object.freeze(copy);
}
Object.defineProperty(obj, key, {value: copy, configurable: true})
}