[ES7] Object.observe + Microtasks
2016-02-17 02:22
399 查看
ES6:
If you know about the Javascirpt's event loop. You know that any asyns opreations will be throwed to the end to loop, such as 'setTimeout, http call'. More
Form:
TO:
It cause the browser render uneffieient, because we may need to wait next time browser render event happen to render our changes.
So what 'Microtasks' does is put notification right after 'event handler' finished:
From:
TO:
---------------------------------
ES7:
How to use Object.observe:
Notice this is in the 'draft' state of ES7, but you can try it out in Chrome, if you enable 'Enable experiment Javascirpt' in 'Chorme:flag'
So when you update the person object, in the console will log out:
Also if the prop is immutable, or delete.. it will log out different 'type'.
If you know about the Javascirpt's event loop. You know that any asyns opreations will be throwed to the end to loop, such as 'setTimeout, http call'. More
Form:
TO:
It cause the browser render uneffieient, because we may need to wait next time browser render event happen to render our changes.
So what 'Microtasks' does is put notification right after 'event handler' finished:
From:
TO:
---------------------------------
ES7:
How to use Object.observe:
Notice this is in the 'draft' state of ES7, but you can try it out in Chrome, if you enable 'Enable experiment Javascirpt' in 'Chorme:flag'
var person = { name: "John" }; Object.observe(person, p => console.log(p));
So when you update the person object, in the console will log out:
/* name: "name" object: Object oldValue: "john" type: "update" */
Also if the prop is immutable, or delete.. it will log out different 'type'.
相关文章推荐
- objective-C学习 NSUserDefaults 相当于缓存
- objective-C学习 自定义对象归档 archiver2
- Objective-C中的alloc和init问题
- Objective-C中的alloc和init问题
- webpack的坑——Object.assign
- SelectObject()函数
- JSONObject与JSONArray的使用
- objective-C学习 sigton单例
- Objective - C NSArray不可变数组和NSMutableArray可变数组
- Windows作业(Job)
- Object类
- GitHub 上Top100 的 Objective-C 项目
- object-c 入门基础篇
- objective-C学习 归档 archiver
- At least one object must implement IComparable
- 把jason字符串转化为标注的data(responseObject)类型
- Objective-C中new与alloc/init的区别
- 什么是不可修改对象(Immutable Object)?你能否写一个例子?
- Objective-C之run loop详解
- error:Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and op