星空网 > 软件开发 > Java

Object.observe将不加入到ES7

先请看 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

Object.observe将不加入到ES7

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

 

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

Over three years ago, Rafael Weinstein, Erik Arvidsson, and I set out todesign and implement what we believed to be the primitive underlying thedata-binding system of MDV ("model-driven views"). We prototyped animplementation in a branch of V8, then got agreement from the V8 team tobuild a real version upstream, while pushing Object.observe ("O.o") as apart of the upcoming ES7 standard and working with the Polymer team tobuild their data-binding system on top of O.o.Three years later, the world has changed in a variety of ways. While otherdata-binding frameworks (such as Ember and Angular) showed interest, it wasdifficult to see how they could evolve their existing model to match thatof O.o. Polymer rewrote from the ground up for its 1.0 release, and in thatrebuilding did not utilize O.o. And React's processing model, which triesto avoid the mutable state inherent in data-binding systems, has becomequite popular on the web.After much discussion with the parties involved, I plan to withdraw theObject.observe proposal from TC39 (where it currently sits at stage 2 inthe ES spec process), and hope to remove support from V8 by the end of theyear (the feature is used on 0.0169% of Chrome pageviews, according tochromestatus.com).For developers who have been experimenting with O.o and are seeking atransition path, consider using a polyfill such ashttps://github.com/MaxArt2501/object-observe or a wrapper library likehttps://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

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境出口电商选品工具:https://www.goluckyvip.com/tag/35336.html
跨境出口电商选品软件:https://www.goluckyvip.com/tag/35337.html
跨境出口电商学习:https://www.goluckyvip.com/tag/35338.html
跨境出口电商有哪些:https://www.goluckyvip.com/tag/35339.html
仓储费:https://www.goluckyvip.com/tag/3534.html
跨境出口电商运营:https://www.goluckyvip.com/tag/35340.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
西藏旅游攻略自驾游需要多少天 去西藏旅游自驾游要多久时间:https://www.vstour.cn/a/363195.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流