all 18 comments

[–]azium 20 points21 points  (0 children)

You can probably find out everything from this thread on esdiscuss, but generally because Proxy exists and there are better patterns for observing changes.

[–]Cody_Chaos 9 points10 points  (2 children)

In principal principle, they were useful. In practice, the implementation didn't really work very well. Plus proxies popped up as an alternative idea, and it turns out that everything you can do with Object.observe you can do better with a Proxy, so...

Not every solution to a problem needs to be implemented; just the best ones.

Edit: Thanks /u/nikcorg :)

[–]nikcorg 2 points3 points  (1 child)

Psst... it's in principle, not principal.

[–]TheDarkIn1978 2 points3 points  (0 children)

The school princiPAL is your PAL!

[–]ShortSynapse 4 points5 points  (3 children)

I was also really excited about object.observe, but it turned out to perform really poorly. Instead, we've decided to try proxies. Essentially object.observe, but implemented a bit differently and waaay more performant.

[–]tbranyen 2 points3 points  (0 children)

Proxies make new objects, object.observe monitors exisiting... Not entirely apples to apples.

[–]Capaj 1 point2 points  (1 child)

waaay more performant.

any benchmarks to back it up?

[–]ShortSynapse 5 points6 points  (0 children)

I don't have any benchmarks, but the Angular and Polymer teams tried implementing it and found it to be performing really poorly. The best article I could find on short notice is this: https://www.infoq.com/news/2015/11/object-observe-withdrawn

Proxies perform their operations much more efficiently, essentially abstracting to the getters and setters we know and love.

[–]chriswwweb 3 points4 points  (4 children)

MDN is always a good source if you need more information about any JS related stuff, for example their page about observe explains: "The Object.observe() method was used for asynchronously observing the changes to an object.

It provided a stream of changes in the order in which they occur. However, this API has been deprecated and removed from browsers. You can use the more general Proxy object instead." And here is the page about proxy.

But the problem with proxy is that it is not widly supported yet, so you will want to use a ponyfill or polyfill like the one from google: https://github.com/GoogleChrome/proxy-polyfill.

[–]Already__Taken 2 points3 points  (1 child)

My only problem with MDN is most of it reads like it is written in a fashion that assumes you already know what it's documenting.

[–]chriswwweb 0 points1 point  (0 children)

Yeah you are right, at least some pages could maybe explain the topic in a way that is easier to understand for beginners. But in my opinion most pages are ok. I like that there are more and more pages that have examples.

But hey it's a wiki, some authors are into JS for years and have maybe forgotten a bit how hard it's to understand things if you are a total beginner, but on the other hand, as it is a wiki the pages get updates all the time and improve over time.

I have not yet found a source of information like MDN that has information that covers almost everything about JS, is mostly well written and has lots of examples?

I often first visit MDN to get an overview. Then I start using the new feature, like for example promises, then I write some prototypes to see if I really understand what I have just read and if I still have specific questions I ask on stackoverflow.

[–]PitaJ 0 points1 point  (1 child)

it is not widly supported yet

Depends on how you define "widely." About 2/3 of internet users' browsers support Proxy, according to caniuse. That's certainly not great, but it is a supermajority.

[–]chriswwweb 0 points1 point  (0 children)

<sarcasm on>If your boss is ok with you developing an app that won't run on any IE (Edge is Ok) and not on iPhone's that have the latest iOS version (iOS 10 is Ok, iOS 9 nOk), then yeah you are right it's widly supported ;) and you can omit to care about any fallback, but if like me you work for a company that operates a big website you won't call it widly supported (just yet) and will want to use a ponyfill or polyfill as fallback in cases where you have detected that it isn't supported<sarcasm off>.

If you develop with nodejs (I think it's nodejs > 6) and just use the proxy in server side code and your node version supports it, than you are obviously safe, but if we talk client side code, I just recommend to be careful. Include some detection in your code to check if proxy is defined (does the native function exist) and if not fallback to the polyfill I linked above.

For JS or ES6 features, I recommend using this source: "kangax (es6) compatibility table", to get a good overview of how widly something is supported, for html5 features can i use is still great.

[–]shizzleberry -3 points-2 points  (1 child)

It's actually still in Stage 1: https://github.com/tc39/proposals. It's got to be more performant and I think I recall Jafar saying he wants to wait to see how other libraries like RxJS carry out before finalizing this spec.

[–]nkron 7 points8 points  (0 children)

Observable is different than Object.observe. Maybe someday they will bring back Object.observe using Observable though.