Open paulirish opened 8 years ago
:+1:
Any help is appreciated!
@paulirish Not sure it is possible in general case -- doesn't Proxy have to be a separate object? So it wouldn't help if you want to watch an object already referenced somewhere.
@ashmind yeah true. the workflow is a little different.
I suppose we could do something like
Object.prototype.debug = function(){
var interceptor = {
set: function (receiver, property, value) {
console.trace(property, 'is changed to', value);
// debugger
receiver[property] = value;
}
};
return new Proxy(this, interceptor);
}
which could enable creating the debuggable object at assignment:
this.latLon = app.getLon().debug();
.... oh look at that, somebody already wrote this: check tracePropAccess
in http://www.2ality.com/2014/12/es6-proxies.html
I suppose one benefit is that you can watch any properties, not just specified ones.
ES6 Proxies could be used to pull off the same technique. It perhaps could have a few advantages over using getters.
They're now in most browsers: