Object.freeze】的更多相关文章

前面提到 ES5 对象属性描述符,这篇看看对象的扩展.密封和冻结. 扩展对象 Object.preventExtensions Object.isExtensible 密封对象 Object.seal Object.isSealed 冻结对象 Object.freeze Object.isFrozen 1. Object.preventExtensions 阻止对象扩展,让一个对象变的不可扩展,也就是永远不能再添加新的属性 ES3 是没有办法阻止对象扩展的,定义对象后可以给对象添加任意属性,如…
Object.freeze方法比Object.seal方法更严格,不仅不能扩展新对象和不可重新配置属性的特性,还不能改变对象属性的值writable(不可写)…
let person = { firstName: "Zhentian", lastName: "Wan" }; /*Object.freeze() makes object cannot be updated, added or deleted*/ let freezePerson = Object.freeze(person); freezePerson.address="Finland"; // Cannot add property ad…
1  Object.seal(O)的调用 When the seal function is called, the following steps are taken:   If Type(O) is not Object throw a TypeError exception.   For each named own property name P of O,      Let desc be the result of calling the [[GetOwnProperty]] int…
我们都知道在js里对象是很容易改变的 var obj1 ={ a:'111' } obj1.a = '222'; console.log( obj.a ) //output 222 对象的属性发生了变化 现在我们来看看es5 给我提供一个对象的新方法冻结对象(浅冻结). Object.freeze(obj) obj是要冻结的对象,Object.freeze()可以防止对象新增属性或方法,防止删除和修改现有的属性和方法.他其实就是让对象变成不可变的数据; var obj = { a:'111' }…
Object.freeze() 方法可以冻结一个对象.一个被冻结的对象再也不能被修改: 冻结了一个对象则不能向这个对象添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性.可配置性.可写性,以及不能修改已有属性的值. 此外,冻结一个对象后该对象的原型也不能被修改.freeze() 返回和传入的参数相同的对象. const obj = { property: 42 }; const obj2 = Object.freeze(obj); obj.property = 33; // Thr…
关键字:seal, freeze, property descriptor. 1.Object.seal() 参考文档(2)中这样描述: The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can…
1.深冻结 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>js 深冻结 与 浅冻结</title> </head> <body> <script type="text/javascript"> function deepFreeze(o) { var prop, propKey Ob…
参考自:https://segmentfault.com/a/1190000006191558 Object.freeze()是ES5新增的特性,可以冻结一个对象,防止对象被修改. vue 1.0.18+对其提供了支持,对于data或vuex里使用freeze冻结了的对象,vue不会做getter和setter的转换. 如果你有一个巨大的数组或Object,并且确信数据不会修改,使用Object.freeze()可以让性能大幅提升. 并且,Object.freeze()冻结的是值,你仍然可以将变…
将对象冻结,使用Object.freeze方法 const foo = Object.freeze({}); // 常规模式时,下面一行不起作用: // 严格模式时,该行会报错 foo.prop = 123; var t = { a:{ t:2 } } //冻结t对象下属性a Object.freeze(t) t.a.t = 3 //不能冻结属性a下的值obj中的对象 console.log(t.a.t) 除了将对象本身冻结,对象的属性也应该冻结.下面是一个将对象彻底冻结的函数. var con…