日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Object.observe将不加入到ES7

發(fā)布時間:2023/12/9 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Object.observe将不加入到ES7 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

先請看?Object.observe 的 API

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

它用來監(jiān)聽對象的變化,當給該對象添加屬性,修改屬性時都會被依次記錄下來

?

看一個示例

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,當數(shù)據(jù)模型發(fā)生變化的時候,通過 Object.observe 的回調(diào)就能方便的監(jiān)聽,通知 View。

?

這是一個強大的功能,可以實現(xiàn)很多MV*庫里的 “雙向綁定”,比如?Angular,Knockout。有了它不必自己去寫一套觀察者代碼,可惜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.

?

?

相關(guān):

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

?

總結(jié)

以上是生活随笔為你收集整理的Object.observe将不加入到ES7的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。