您的位置:首页 > 移动开发 > Objective-C

[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'

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'.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: