Object.observe inital polyfill
wraped VS wrapped ... also setInterval there accepts arguments after the delay so no need to use 2 functions
setInterval(theInternalFn, 100, wraped); // changed with the proper name or ... you know what? no need at all to pass the argument, isn't it, the function is already in the same outer scope than wrapped is.
Minor things like this a part, the polling is a no-go, imho, as you might miss changes in the middle that were absolutely fundamental for your logic, i.e. resetting something when size = 0; or stuff like that.
Last, but not least, if this script is for node.js only or modern browsers, the best way to implement observe() is via Proxy, changing only one thing: you need to re address and use the observed object rather than use the normal one.
Last, but not least, I was working on some alternative solution based on get/set thought, able to bring this stuff in ES3 capable environments too. Maybe we can share some thoughts on it a part.
br
2012/11/30 Andrea Giammarchi <andrea.giammarchi at gmail.com>
Last, but not least, if this script is for node.js only or modern browsers, the best way to implement observe() is via Proxy, changing only one thing: you need to re address and use the observed object rather than use the normal one.
See < tvcutsem/harmony-reflect/blob/master/examples/observer.js>
for an implementation of that approach (usage example is here < tvcutsem/harmony-reflect/blob/master/examples/observer.html
.
It was based on the original spec. for Object.observe. It may not be up-to-date with the latest version though.
We are looking at using Object.observe in a current project as it will ease our development time greatly. To that avail I've created a simple (call it proof of concept) polyfill/shim (whats the difference?) ( jdarling/Object.observe) that compares quite well with the Chromium build that includes Object.observe.
I know Object.observe is only a proposal but the idea was so close to our existing binding solution that it is worth expanding upon.
I noticed a few things though after posting it up: According to the email at esdiscuss/2012-August/024759.htmlObject.observe does not pay attention to calculated properties. To me this mean properties surfaced through defineProperty() that have a getter, is this true (I was planning on adding better support for this if I'm wrong).
Notifier.NotifierPrototype isn't well defined, so I left it out currently. Can you provide a high level of what exactly it should look like?
For getNotifier() I'm using a self sealing/modifying solution. Does this seem appropriate or is there a better way?
Finally, setTimeout, etc pass back an indexer that can be used for clearing rather than having to maintain the actual method. This helps when using anonymous functions as the callback. Is there a reason that Object.observe returns a full object that can't be used to clear the observation, or did I miss something?
I know I'm using polling, but I want to know just how close I have got. According to the test scripts I've found and my own tests I'm fairly close. If it is then I plan on using getters/setters and property overrides to get better response times. I just want community feedback first to make sure.