问题
Which browsers, if any, support Object.observe
? I'm surprised I'm unable to find any info on this.
(And are you aware about any estimated times of arrival for this feature?)
About Object.observe: "Object.observe allows for the direct observation of changes to ECMAScript objects. It allows an observer to receive a time-ordered sequence of change records which describe the set of changes which took place to the set of observed objects." — see ecmascript.org, the Solution section.)
Edit November 2015: Apparently Object.observe has been cancelled:
http://www.infoq.com/news/2015/11/object-observe-withdrawn
https://esdiscuss.org/topic/an-update-on-object-observe
"I plan to withdraw the Object.observe proposal from TC39"
https://esdiscuss.org/topic/save-object-observe-please-make-weakmap-weakset-observable
"Save Object.observe()! (please)"
回答1:
No browsers. If its not true today, it will be true someday, and then this can be the accepted answer.
回答2:
You can use kangax's Browser Compatibility Table for Object.observe
It is part of ECMA Script 7 Specifications, it seems. Luckily, at the time of this writing, my current browser, Chrome 33, is the only one which supports it :)
If you like to enable it in Chrome 33,
Visit
chrome://flags/
And enable
Enable Experimental JavaScript
回答3:
Polymer is a new and promising framework that intends to implement Web Components, for which Object.observe()
is an integral part.
It provides polyfill implementation for "evergreen" browsers; the latest ones available. Moreover, they track what browser have native support for this feature, so it speeds up their implementation.
This polyfill is available as a separate library on GitHub.
回答4:
Chrome 35+ supports Object.observe() Method.
More details here: html5rocks
Update: It's moved to chrome 36 beta.
回答5:
It used to be present in both Chrome & Opera, but the feature has been removed from both browsers after the standards committee withdrew the proposal for this feature!
回答6:
Chrome 36+, Opera 30+. My favorite way of answering these questions is http://caniuse.com. It's clear, consice, and has instant search.
回答7:
Disclaimer: I'm the author of object-observer library.
basarat's answer is definitelly the right one - nowadays no browser supports it.
Most of the polyfills performing 'dirty-checks' - not the best way to achieve observance IMHO.
Better way is to pick up one of the several libraries providing the same functionality utilizing native Proxy capabilities, object-observer being just one of them.
来源:https://stackoverflow.com/questions/21073082/which-browsers-support-object-observe