码迷,mamicode.com
首页 > 其他好文 > 详细

[ES7] Object.observe + Microtasks

时间:2016-02-17 06:05:04      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

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‘

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

[ES7] Object.observe + Microtasks

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5194179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!