关键字: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

最新文章

  1. 关于for、foreach、filter等的一些用法
  2. Sprint回顾_团队听诊器
  3. Android Gradle 技巧之一: Build Variant 相关
  4. 自定义Adapter
  5. 快捷设置IE代理小工具
  6. php中json_decode()和json_encode()
  7. 从APP消息推送所理解的观察者模式
  8. 将主机IDS OSSEC日志文件存入MYSQL的方法
  9. python学习笔记(一)之入门
  10. android应用开发基础知道
  11. js计算元素距离顶部的高度及元素是否在可视区判断
  12. TCP的定时器系列 — 零窗口探测定时器
  13. (办公)mysql连接不上(java.sql.SQLException: null, message from server: "Host 'LAPTOP-O0GA2P8J' is not allowed to connect to this MySQL server")(转)
  14. Web 端异步下载文件
  15. Yum安装时出现 The program yum-complete-transaction is found in the yum-utils package
  16. LINUX第三次实践:程序破解
  17. 关于windows中80端口被占用
  18. [BZOJ5139][Usaco2017 Dec]Greedy Gift Takers 权值线段树
  19. python面试题(转自https://www.cnblogs.com/wupeiqi/p/9078770.html)
  20. PAT乙级1030

热门文章

  1. arcgis求邻接矩阵
  2. Git2:Git基本操作
  3. python---基础知识回顾(五)(python2.7和python3.5中的编码)
  4. 无法将网络更改为桥接状态 没有VMent0
  5. Django 2.0.1 官方文档翻译: 文档目录 (Page 1)
  6. 取消IE下的叉
  7. APScheduler定时执行外加supervisor管理后台运行
  8. 美轮美奂!9款设计独特的jQuery/CSS3全新应用插件(下拉菜单、动画、图表、导航等)
  9. java 创建最大堆
  10. Callable,Future,FutureTask