关键字: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 still be changed as long as they are writable.

主要就是两点:

  1. 阻止添加新属性;
  2. 现有属性变得non-configurable.

第一点好理解;第二点需要搞清楚non-configurable是什么意思,configurable在这篇博文中有详细解释,

这里再贴一遍:

当configurable设为false时,

  1、不可以通过delete去删除该属性从而重新定义属性;

  2、不可以转化为访问器属性;

  3、configurable和enumerable不可被修改;

  4、writable可单向修改为false,但不可以由false改为true;

  5、value是否可修改根据writable而定。

理解了configurable的意思,也就能理解为啥会有这个句话了:被封的对象仍可能可以修改对象的属性值。

Values of present properties can still be changed as long as they are writable.

2、Object.freeze()

参考文档(3)中这样描述:

The Object.freeze() method freezes an object. A frozen object can no longer be changed;

freezing an object prevents new properties from being added to it,

existing properties from being removed,

prevents changing the enumerability, configurability, or writability of existing properties,

and prevents the values of existing properties from being changed.

In addition, freezing an object also prevents its prototype from being changed.

  此函数“冰冻”对象本身以及一切现有的属性值(value)以及属性的特性(property descriptor)。

在函数Object.seal()中也许还可以修改属性值以及修改 属性的特性writable(true-->false),

但是在Object.freeze()中,这些都干不了。

参考文档:

(1)https://www.cnblogs.com/tlz888/p/10389532.html

(2)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal

(3)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze

js中的Object.seal()与Object.freeze()的更多相关文章

  1. js中的new操作符与Object.create()的作用与区别

    js中的new操作符与Object.create()的作用与区别 https://blog.csdn.net/mht1829/article/details/76785231 2017年08月06日 ...

  2. ECMA5.1中Object.seal()和Object.freeze()的区别

    1  Object.seal(O)的调用 When the seal function is called, the following steps are taken:   If Type(O) i ...

  3. JS中的相等性判断===, ==, Object.is()

    首发地址:http://www.geeee.top/2019/11/15/equality-comparisons/,转载请注明出处 相信刚接触JS的人都会被他的想等性判断给整糊涂,看看下面代码,你能 ...

  4. 小tips:JS中this操作执行像(object.getName = object.getName)()操作改变了this

    var name = "The window"; var object = { name: "My Object", getName: function(){ ...

  5. js中的window.open返回object的错误

    系统中用javascript中的window.open后,页面返回了一个[object].因为系统的原因,必需使用href="javascript:window.open()"这样 ...

  6. ES5 对象的扩展(Object.preventExtensions)、密封(Object.seal)和冻结(Object.freeze)

    前面提到 ES5 对象属性描述符,这篇看看对象的扩展.密封和冻结. 扩展对象 Object.preventExtensions Object.isExtensible 密封对象 Object.seal ...

  7. 浅解析js中的对象

    浅解析js中的对象 原文网址:http://www.cnblogs.com/foodoir/p/5971686.html,转载请注明出处. 前面的话: 说到对象,我首先想到的是每到过年过节见长辈的时候 ...

  8. js基础知识温习:js中的对象

    在JavaScript中对象是一个无序属性的集合,其属性可以包含基本值.对象或者函数. 对象最简单的创建方式 JavaScript中创建对象最简单的方式就是创建一个Object对象的实例,然后再添加属 ...

  9. 关于js中的时间处理

    关于js编程, 主要是, 绝大部分是用 jquery. 但是, js原生的一些方法和属性也是要掌握的, 这个只是在 遇到的时候, 记一下就好了, 如: event的relatedTarget属性: 主 ...

随机推荐

  1. git<撤销本地修改与回退版本>

    1. 使用 git checkout 撤销本地修改 即放弃对本地已修改但尚未提交的文件的修改,还原其到未修改前的状态. 注意: 已 add/ commit 的文件不适用个方法,应该用本文提到的第二种方 ...

  2. Service Fabric Failover Manager

    作者:潘罡 (Van Pan)@ Microsoft 什么是Failover Manager 我们回到Service Fabric系统架构图. Failover Manager是Reliability ...

  3. python pop()

    pop() 函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值. obj -- 可选参数,要移除列表元素的索引值,不能超过列表总长度,默认为 index=-1,删除最后一个列表值 l ...

  4. python 资产扫描01

    本地建立的三个文件: Asset1.txt 用来保存扫描到的资产 Asset2.txt 用来导入给定的资产 Repeat.txt 保存重复的资产 程序的功能: 1.资产扫描,以 位置:资产 格式保存到 ...

  5. numpy/arrayobject.h”: No such file or directory

    import numpyimport pyximportpyximport.install(setup_args={"script_args":["--compiler= ...

  6. table 样式美化

    1. 单像素边框CSS表格 这是一个很常用的表格样式. 源代码: <!-- CSS goes in the document HEAD or added to your external sty ...

  7. Linux入门,这七大习惯得有!

    对于很多Linux初学者来说,在刚开始使用Linux系统时会感到很多不适.这里为大家整理了自己以前Linux入门时别人告诉我的七个习惯.我相信如果你运用了这七个习惯,在你使用Linux时你会感觉更安全 ...

  8. java selenium常用API(WebElement、iFrame、select、alert、浏览器窗口、事件、js) 一

     WebElement相关方法 1.点击操作 WebElement button = driver.findElement(By.id("login")); button.clic ...

  9. [转载]jsonp详解

    http://www.cnblogs.com/lemontea/archive/2012/12/11/2812268.html json相信大家都用的多,jsonp我就一直没有机会用到,但也经常看到, ...

  10. 【译】第六篇 Integration Services:初级工作流管理

    本篇文章是Integration Services系列的第六篇,详细内容请参考原文. 简介在前几篇文章中,我们关注使用增量加载方式加载数据.在本篇文章,我们将关注使用优先约束管理SSIS控制流中的工作 ...