It's been a few years, but he did a great job for me. An SO user published an open source surveillance object several years ago. It changes the prototype of the object so that you track changes in certain properties of the object.
window.watch('onclick', function() { console.log('changed'); }); window.onclick = function() { console.log('click1'); }; window.onclick = function() { console.log('click2'); };
JSFiddle: https://jsfiddle.net/gou48xpa/
Source code: https://gist.github.com/eligrey/384583 (released under the MIT license)
if (!Object.prototype.watch) { Object.defineProperty(Object.prototype, "watch", { enumerable: false , configurable: true , writable: false , value: function (prop, handler) { var oldval = this[prop] , newval = oldval , getter = function () { return newval; } , setter = function (val) { oldval = newval; return newval = handler.call(this, prop, oldval, val); } ; if (delete this[prop]) {
source share