关键字: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. Redis3未授权访问漏洞导致服务器被入侵

    今天在腾讯云上搭的开发环境里的一台机器cpu load飚升老高,然后还能登陆上去,top后发现两个可疑进程./root/目录下有修改过的文件./opt目录被干掉了, 后经分析,这台机器上有redis外 ...

  2. python3.5无法安装pip,报错ImportError: cannot import name 'HTTPSHandler'

    本人系统为:centos6 解决方法: 1  安装openssl yum install openssl 2  安装openssl-devel yum install openssl-devel 3  ...

  3. html5 +css3 点击后水波纹扩散效果 兼容移动端

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. webApp 页面适配布局

    webApp 页面布局 1. 流式布局 概念: 流式布局是页面元素宽度按照屏幕分辨率进行适配调整,但是整体布局不变. 设计方法: 布局都是通过百分比来定义宽度,但是高度大都是用px固定的. 弊端: 虽 ...

  5. ssh 批量执行命令

    # python3.5 + paramiko # pip 是python的包管理工具,在shell里执行如下命令安装paramoko模块 # pip install paramiko # import ...

  6. 监控redis数据库应用状态:python,tornado实现

    公司里最近redis服务器压力越来越大,其大概情况,只能从操作系统层面看,并不详尽,故同事在网上找了一个叫做 redis-live的开源项目,我配合部署了一下,还真有点意思,并解决了其中部分小debu ...

  7. SQL查找数据库中所有没有主键的数据表脚本

    --SQL查找数据库中所有没有主键的数据表脚本 --运行脚本后在消息中可能会显示下面现象中的一种:--(1)数据库中所有数据表都有主键(则证明所有数据表都有主键)--(2)当前数据表[数据表名]没有主 ...

  8. HDU 2391 Filthy Rich (dp)

    题目连接 Problem Description They say that in Phrygia, the streets are paved with gold. You're currently ...

  9. Hive笔记之导出查询结果

    一.导出到本地 导出查询结果到本地: INSERT OVERWRITE LOCAL DIRECTORY "/tmp/hive-result/t_visit_video" SELEC ...

  10. python3学习笔记.4.turtle绘图

    先放上参考 https://docs.python.org/3/library/turtle.html //********************************************** ...