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的更多相关文章

  1. 浅解析js中的对象

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

  2. My ECMAScript 7 wishlist

    With ECMAScript 6 now feature complete, any further changes to the core of JavaScript will happen in ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. [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. ...

  7. [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 ...

  8. javascript EcmaScript5 新增对象之Object.freeze

    我们都知道在js里对象是很容易改变的 var obj1 ={ a:'111' } obj1.a = '222'; console.log( obj.a ) //output 222 对象的属性发生了变 ...

  9. (74)Wangdao.com第十三天_Object 对象_属性描述对象

    Object 对象 JavaScript 原生提供 Object 对象 JavaScript 的所有其他对象都继承自  Object 对象,即那些对象都是Object的实例 Object 对象的原生方 ...

随机推荐

  1. Java反射学习-3 - 反射获取属性,方法,构造器

    package cn.tx.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import ...

  2. vue.js(12)--过滤器

    vue中的全局过滤器与定义私有过滤器 全局过滤器 <!DOCTYPE html> <html lang="en"> <head> <met ...

  3. AOS and clustering

    原文转载:http://sjakalax.blogspot.com/2010/10/aos-and-clustering.html AOS and clustering   hi,   There s ...

  4. 彻底解决mysql报错:1030, 'Got error 28 from storage engine'

    权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/harry5508/article/deta ...

  5. 如何在Linux下手动编译安装gcc

    如果可以通过apt来安装的话,尽量不要手工编译了,手工编译是最后的选择.用apt安装,只需要输入一条命令: sudo apt-get install gcc 手工编译的话,gcc和其他软件包存在如下的 ...

  6. 使用BaGet来管理内部Nuget包

    有的时候,我们想要制作一些nuget包,供自己内部调用,不想公开出去,那么就需要一个能够集中管理nuget包的服务了,今天我来给大家介绍一款轻便好用的包管理服务-----BaGet 下载并部署BaGe ...

  7. python基础--2 字符串

    整型 int python3里,不管数字多大都是int类型 python2里面有长整型long 将整型字符串转换为数字 # a='123' # print(type(a),a) # b=int(a) ...

  8. sed \s

    export m1=`free|cut -d ":" -f2|sed -e "s/^\s\s*//g"|head -2|tail -1|cut -d ' ' - ...

  9. Android App渗透测试工具汇总

    网上搜集了一些App安全学习教程及工具,项目地址:https://github.com/Brucetg/App_Security 一. drozer简介 drozer(以前称为Mercury)是一款A ...

  10. easyui for jquery之tooltip

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...