One of the much-promised features coming in the ECMAScript 2016 specification was Object.observe
. It promised us the ability to watch objects for changes and react accordingly, akin to two-way binding found in frameworks like Angular 1.x.
However, Adam Klein one of three people responsible for introducing the idea of Object.observe
is withdrawing the proposal from TC39 which is currently at stage 2 in the process and also hopes to remove it from V8 (Chrome’s Javascript engine) by the end of the year.
I actually completely understand the change of heart and support this decision. Adam is right, a lot of developers originally wanted something like Object.observe
, but better solutions presented themselves. Object.observe
was always going to introduce complexities and bad side-effects into our applications.
Thanks in part to React.js, a lot of people in the community realised there is a much better way to observe changes without dirty checking. Instead, we can use getters/setters and in some cases (like form elements) we can use event callbacks.
In the latest version of Polymer you can see first-hand what data-binding looks like without dirty-checking or Object.observe
. Of all of the libraries/frameworks out there, if observing objects was the way to go, Polymer would have introduced support for doing so.
I have experienced too many times to count the issues that can arise from dirty-checking (like in Angular 1.x). I even witnessed a deadline missed because of the performance implications of dirty-checking in Angular.
Even though the addition of Object.observe
would have meant no dirty checking, theoretically you can still encounter performance issues if you’re not careful with how many objects and properties you are watching.
I think those who wanted it, thought it would be some cure-all silver-bullet, when in-fact using getters and setters on your objects, you can effectively achieve the same thing (and the performance is substantially better as well).
Now we just have to eagerly await for better Proxy support and hopefully we see some native support for immutability in Javascript if the specification is starting to become influenced by React.js.
So while many despise React.js and its JSX allowing CSS in Javascript, we have it to thank for Object.observe
support being dropped. Oh, and yes, this means Array.observe
is also dropped.