首页 > 其他 > 详细

[ES7] Object.observe + Microtasks

时间:2016-02-17 06:04:50      阅读:200      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!