Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects.

/*
* Open the console to see
* that the tests have passed.
*/ const toggleTodo = (todo) => {
return {
...todo,
completed: !todo.completed
};
}; const testToggleTodo = () => {
const todoBefore = {
id: 0,
text: 'Learn Redux',
completed: false
};
const todoAfter = {
id: 0,
text: 'Learn Redux',
completed: true
}; deepFreeze(todoBefore); expect(
toggleTodo(todoBefore)
).toEqual(todoAfter);
}; testToggleTodo();
console.log('All tests passed.');

Here '...todo', spread object, whcih is not available in ES6, but will be in ES7, It is fairly popular, and it is enabled in Babel if you use the stage two preset.

https://babeljs.io/docs/plugins/preset-stage-2/

[Redux] Avoiding Object Mutations with Object.assign() and ...spread的更多相关文章

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

  2. est6 -- Object.is()、Object.assign()、Object.defineProperty()、Symbol、Proxy

    Object.is()用来比较两个值是否严格相等.它与严格比较运算符(===)的行为基本一致,不同之处只有两个:一是+0不等于-0,二是NaN等于自身. + === - //true NaN === ...

  3. Object的create、assign、getPrototypeOf与拷贝

    Object的create.assign.getPrototypeOf与拷贝:https://www.cnblogs.com/ninalei/p/8655567.html

  4. Object.create 和 Object.assign

    Object.assign(target, ...source) 1.Object.assign方法只会拷贝源对象自身(不包括原型)的并且可枚举的属性到目标对象,使用源对象的get和目标对象的set, ...

  5. Object obj=new Object()的内存引用

    Object obj=new Object(); 一句很简单的代码,但是这里却设计Java栈,Java堆,java方法去三个最重要的内存区域之间的关联. 假设这句代码出现在方法体中. 1.Object ...

  6. host Object和native Object的区别

    Native Object: JavaScript语言提供的不依赖于执行宿主的对象,其中一些是内建对象,如:Global.Math:一些是在脚本运行环境中创建来使用的,如:Array.Boolean. ...

  7. Intent传递List和Object和List<Object>

    一.传递List 传递List<String>的方法 小技巧,List<object> 可以使用json 转为 List<string>,就可以使用 List< ...

  8. JavaScript中in操作符(for..in)、Object.keys()和Object.getOwnPropertyNames()的区别

    ECMAScript将对象的属性分为两种:数据属性和访问器属性.每一种属性内部都有一些特性,这里我们只关注对象属性的[[Enumerable]]特征,它表示是否通过 for-in 循环返回属性,也可以 ...

  9. iOS 杂笔-21(self.name = “object” 和 _name =”object” 有什么不同?)

    iOS 杂笔-21(self.name = "object" 和 _name ="object" 有什么不同?) 问题如题,这是考察对属性与变量的了解而已. s ...

随机推荐

  1. 一些iOS笔试题目

    1.什么是arc?(arc是为了解决什么问题诞生的?) 首先解释ARC: automatic reference counting自动引用计数. ARC几个要点: 在对象被创建时 retain cou ...

  2. tableView Crash

    转自:http://blog.csdn.net/hamasn/article/details/8613593 Assertion failure in -[UITableView _configure ...

  3. 无法升级数据库....因为此版本的 SQL Server 不支持该数据库的非发布版本(539) 解决方案

    使用SQL2012附加一个数据库时报出了以下错误:“无法升级数据库....因为此版本的 SQL Server 不支持该数据库的非发布版本(539).不能打开与此版本的 sqlserver.exe 不兼 ...

  4. WPF Binding

    winform有binding, WPF也有binding,区别在哪呢?这里暂时不提.以前也检查接触WPF binding, 但为什么过段时间就忘记了呢? 可能主要原因自己的知识体系不够完善吧,下面我 ...

  5. JavaScript--赋值表达式(typeof-delete-void)

    typeof运算符 typeof是一个一元运算符,操作数可以使任意类型,返回值为操作数类型的一个字符串 一.数字类型,如typeof(1),返回的值就是number.当然这个是常规数字,对于非常规的数 ...

  6. RemoteWebDriver使用说明

    1. 本地代码使用RemoteWebDriver启动: public class Testing { public void myTest()throws Exception { WebDriver ...

  7. Java JNDI Datasource HOW-TO Problem

    在开发JAVA的时候发生了点问题,解决方案记录一下,在这里http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto. ...

  8. oracle行转列和列转行

    目录[-] 一.行转列 1.1.初始测试数据 1.2. 如果需要实现如下的查询效果图: 1.3.延伸 二.列转行 1.1.初始测试数据 1.2. 如果需要实现如下的查询效果图: 一.行转列 1.1.初 ...

  9. LIKE匹配关键字

    1.% 匹配任意数目字符(包括零个字符) SELECT * FROM edo_user WHERE true_name LIKE '王%' 应用:关键字查询 WHERE u.true_name lik ...

  10. jquery easy ui 学习 (2) customtools window

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