deepFreeze
obj1 = {
internal: {}
}; Object.freeze(obj1);
obj1.internal.a = 'aValue'; obj1.internal.a // 'aValue' // To make obj fully immutable, freeze each object in obj.
// To do so, we use this function.
function deepFreeze(obj) { // Retrieve the property names defined on obj
var propNames = Object.getOwnPropertyNames(obj); // Freeze properties before freezing self
propNames.forEach(function(name) {
var prop = obj[name]; // Freeze prop if it is an object
if (typeof prop == 'object' && prop !== null)
deepFreeze(prop);
}); // Freeze self (no-op if already frozen)
return Object.freeze(obj);
} obj2 = {
internal: {}
}; deepFreeze(obj2);
obj2.internal.a = 'anotherValue';
obj2.internal.a; // undefined
deepFreeze的更多相关文章
- 浅解析js中的对象
浅解析js中的对象 原文网址:http://www.cnblogs.com/foodoir/p/5971686.html,转载请注明出处. 前面的话: 说到对象,我首先想到的是每到过年过节见长辈的时候 ...
- My ECMAScript 7 wishlist
With ECMAScript 6 now feature complete, any further changes to the core of JavaScript will happen in ...
- [Redux] Reducer Composition with Arrays
In the previous lesson we created a reducer that can handle two actions, adding a new to-do, and tog ...
- [Redux] Writing a Todo List Reducer (Toggling a Todo)
Learn how to implement toggling a todo in a todo list application reducer. let todo = (state = [], a ...
- [Redux] Writing a Todo List Reducer (Adding a Todo)
Learn how to implement adding a todo in a todo list application reducer. let todo = (state = [], act ...
- [Redux] Avoiding Object Mutations with Object.assign() and ...spread
Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects. ...
- [Redux] Avoiding Array Mutations with concat(), slice(), and ...spread
For Redux, you cannot use mutable methods like push, splice. Need to use immutable methods such as c ...
- javascript EcmaScript5 新增对象之Object.freeze
我们都知道在js里对象是很容易改变的 var obj1 ={ a:'111' } obj1.a = '222'; console.log( obj.a ) //output 222 对象的属性发生了变 ...
- (74)Wangdao.com第十三天_Object 对象_属性描述对象
Object 对象 JavaScript 原生提供 Object 对象 JavaScript 的所有其他对象都继承自 Object 对象,即那些对象都是Object的实例 Object 对象的原生方 ...
随机推荐
- 解决本地mysql服务允许被外部主机连接
今天在网上百度看了怎么使用外部主机连接本地MySQL服务,发现大多的说法都是不全面的,试了好久,整理下: 1.现创建了一个mysql用户,并赋予常用的操作权限 CREATE USER 'mysql'@ ...
- 剑指offer--字符串
C/C++中每个字符串都以字符'\0'作为结尾,这样我们就可以很方便的找到字符串最后的尾部.由于这个特点,每个字符串中都有一个额外字符的开销,稍不留神就会造成字符串的越界. 为了节省内存,C/C++把 ...
- 时间选择器moment格式化存在时差问题
时间选择器moment格式化存在时差问题解决方法: return moment(date).utc().zone(+6).format('YYYY-MM-DD')解决IE9时间选择器不能回显数据解决方 ...
- HBase的访问方式
这里只介绍三种最常用的方式 1.HBase shell HBase的命令行工具是最简单的接口,主要用于HBase管理 首先启动HBase 帮助 hbase(main):001:0> help 查 ...
- .NET Reactor使用教程(加密源代码示例)
更多:https://www.cnblogs.com/PiaoMiaoGongZi/category/1120300.html 1.打开 Eziriz .NET Reactor,主界面如图1所示: 图 ...
- Python3安装教程
目录 1. 推荐阅读 2. 安装包下载 3. 安装步骤 1. 推荐阅读 Python基础入门一文通 | Python2 与Python3及VSCode下载和安装.PyCharm破解与安装.Python ...
- 手机端 css 样式重置
@charset "utf-8"; body, div, ul, li, ol, h1, h2, h3, h4, h5, h6, input, textarea, select, ...
- c++ sizeof的实现
c++中的sizeof,可以通过以下宏定义实现. #include <stdio.h> #define sizeof_T(T) ((size_t)((T*)0+1)) ///求类型的大小 ...
- Python链接liunx 带尝试
本文实例讲述了python下paramiko模块实现ssh连接登录Linux服务器的方法.分享给大家供大家参考.具体分析如下: python下有个paramiko模块,这个模块可以实现ssh登录lin ...
- process-hacker
https://github.com/processhacker/processhacker#process-hacker // begin_phapppub typedef enum _PH_KNO ...