[Redux] Avoiding Object Mutations with Object.assign() and ...spread
2015-11-30 03:31
423 查看
Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects.
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/
/* * 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/
相关文章推荐
- 关于EnumerateObjectsUsingBlock和for-in之间的较量
- 字典里的value值的类型是是object的类型,不能想当然的去调用其他方法。
- object中几个有趣的方法!
- Object Detection Networks on Convolutional Feature Maps
- WebKit之addToJavaScriptWindowObject()分析
- Page Object Model (Selenium, Python)
- 黑马程序员——Java笔记——Object类
- Objective-C 继承和多态
- 自学objective-c,靠什么坚持?
- 黑马程序员--eclipse和Object类(day08)
- Objective-C(一)面向对象
- 熟悉Objective—C
- Object-C,循环语句for,while,do-while
- Object-C,循环语句for,while,do-while
- Object-C,循环语句for,while,do-while
- Objective-C:swift、objective-c、C++、C混合编程
- RegAsm注册DLL组件使用jacob调用的问题com.jacob.com.ComFailException: Can't co-create object
- (一)Course Learning Objectives【The Arduino Platform and C Pro】
- Object-C,文件路径API
- Object-C,文件路径API