先请看 Object.observe 的 API

Object.observe(obj, callback[, acceptList])

它用来监听对象的变化,当给该对象添加属性,修改属性时都会被依次记录下来

看一个示例

var person = {}
Object.observe(person, function(arr) {
var change = arr[0]
console.log(change.type, change.name, change.oldValue)
})

在 chrome 控制台里修改 person

可以看到给 person 添加、修改和删除属性都没记录下来了。这个 person 可以看出是 MV* 里的 Model,当数据模型发生变化的时候,通过 Object.observe 的回调就能方便的监听,通知 View。

这是一个强大的功能,可以实现很多MV*库里的 “双向绑定”,比如 AngularKnockout。有了它不必自己去写一套观察者代码,可惜ES7最终将它放弃

Over three years ago, Rafael Weinstein, Erik Arvidsson, and I set out to
design and implement what we believed to be the primitive underlying the
data-binding system of MDV ("model-driven views"). We prototyped an
implementation in a branch of V8, then got agreement from the V8 team to
build a real version upstream, while pushing Object.observe ("O.o") as a
part of the upcoming ES7 standard and working with the Polymer team to
build their data-binding system on top of O.o. Three years later, the world has changed in a variety of ways. While other
data-binding frameworks (such as Ember and Angular) showed interest, it was
difficult to see how they could evolve their existing model to match that
of O.o. Polymer rewrote from the ground up for its 1.0 release, and in that
rebuilding did not utilize O.o. And React's processing model, which tries
to avoid the mutable state inherent in data-binding systems, has become
quite popular on the web. After much discussion with the parties involved, I plan to withdraw the
Object.observe proposal from TC39 (where it currently sits at stage 2 in
the ES spec process), and hope to remove support from V8 by the end of the
year (the feature is used on 0.0169% of Chrome pageviews, according to
chromestatus.com). For developers who have been experimenting with O.o and are seeking a
transition path, consider using a polyfill such as
https://github.com/MaxArt2501/object-observe or a wrapper library like
https://github.com/polymer/observe-js.

相关:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe

https://github.com/polymer/observe-js

https://github.com/MaxArt2501/object-observe

https://mail.mozilla.org/pipermail/es-discuss/2015-November/044684.html

Object.observe将不加入到ES7的更多相关文章

  1. [ES7] Object.observe + Microtasks

    ES6: If you know about the Javascirpt's event loop. You know that any asyns opreations will be throw ...

  2. 【JavaScript】Object.observe()带来的数据绑定变革

    Object.observe()带来的数据绑定变革 引言 一场变革即将到来.一项Javascript中的新特性将会改变你对于数据绑定的所有认识.它也将改变你所使用的MVC库观察模型中发生的修改以及更新 ...

  3. Object.observe() 观察对象

    这个对象方法可以用来异步观察对javascript对象的改动: // Let's say we have a model with data var model = {};   // Which we ...

  4. object.observe数据绑定

    object.observe方法格式如下: object.observe(object,callback) 监听object对象,当该对象有新增或更新或删除等操作,就会触发callback,就实现了双 ...

  5. Object.observe

    使用Object.observe 实现数据绑定

  6. 使用Object.observe 实现数据绑定

    Object.observe API概述 最近,JavaScript的MVC框架在Web开发届非常盛行.在实现MVC框架的时候,一个非常重要的技术就是数据绑定技术.如果要实现模型与视图的分离,就必须要 ...

  7. object.observe被废弃了怎么办

    用新的 Proxy 具体见:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Proxy

  8. MVVM双向绑定实现之Object.defineProperty

    随着web应用的发展,直接操作dom的应用已渐行渐远,取而代之的是时下越来越流行的MVVM框架,dom操作几乎绝迹,这里面自然是框架底层封装的结果.MVVM框架的双向数据绑定使开发效率大大提高:然后在 ...

  9. javascript ES5 Object对象

    原文:http://javascript.ruanyifeng.com/stdlib/object.html 目录 概述 Object对象的方法 Object() Object.keys(),Obje ...

随机推荐

  1. Net设计模式实例之抽象工厂模式(Abstract Factory Pattern)

    一.抽象工厂模式简介(Bref Introduction) 抽象工厂模式(Abstract Factory Pattern),提供一个创建一系列相关或者相互依赖对象的接口,而无需制定他们的具体类.优点 ...

  2. Xamarin.Android之给我们的应用加点过渡效果

    零.前言 试想一下,我们的应用正在请求一些数据,假设网络不是很好,要花比较长的时间等待,这个时候界面什么反应也没有, 一动不动,用户可能就会认为应用挂掉了,这么久都没反应的,说不定下一分钟用户就把它卸 ...

  3. jQuery on()方法

    jQuery on()方法是官方推荐的绑定事件的一个方法. $(selector).on(event,childSelector,data,function,map) 由此扩展开来的几个以前常见的方法 ...

  4. MySQL数据迁移到MSSQL-以小米数据库为例-测试828W最快可达到2分11秒

    这里采用.NET Framework 4.0以上版本中新出现的 ConcurrentQueue<T> 类 MSDN是这样描述的: ConcurrentQueue<T> 类是一个 ...

  5. Overload 和Override 的区别

    Overload 是重载的意思,Override 是覆盖的意思,也就是重写.重载 Overload 表示同一个类中可以有多个名称相同的方法,但这些方法的参数列表各不相同(即参数个数或类型不同).重写 ...

  6. luogg_java学习_12_线程

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 线程 程序.进程.线程的概念 程序:我们用程序设计语言 ...

  7. laravel 使用artisan命令新增数据库字段

    php artisan make:migration create_comments_table <?php use Illuminate\Database\Schema\Blueprint; ...

  8. 高性能 TCP & UDP 通信框架 HP-Socket v3.2.3

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  9. cocos2d-x3.3 以前版本 工程Xcode6编译时的问题

    Undefined symbols for architecture i386: "_fwrite$UNIX2003", referenced from: _unixErrorHa ...

  10. 低调奢华 CSS3 transform-style 3D旋转

    点击这里查看效果:http://keleyi.com/a/bjad/s89uo4t1.htm 效果图: CSS3 transform-style 属性 以下是代码: <!DOCTYPE html ...