I am using Object.observe() on node v0.11.13.
It looks like the time of the observation callback to be called can't be predicted. is it a bug or a feature?
Take a look at this code:
function observe(obj,name){
Object.observe(obj, function(o){
console.log(name,o);
});
return obj;
}
var boo = observe({foo:1},'a');
var doo = observe({foo:1},'b');
doo.foo=2;
boo.foo=2;
The output looks like:
a [ { type: 'update', object: { foo: 2 }, name: 'foo', oldValue: 1 } ]
b [ { type: 'update', object: { foo: 2 }, name: 'foo', oldValue: 1 } ]
I would expect an opposite order. I wonder if this is related to the spec or to node impl' of this feature.
It seems to be following the order in which observers are registered rather than the order in which values are changed.
That makes sense, because multiple changes to the same object during a synchronous run through execution stack processing will be batched together.