Skip to content

Instantly share code, notes, and snippets.

@stevemao
Created January 22, 2016 04:19
Show Gist options
  • Save stevemao/6f71429a08103c9bc7e0 to your computer and use it in GitHub Desktop.
Save stevemao/6f71429a08103c9bc7e0 to your computer and use it in GitHub Desktop.
console = console || {}; // just in case
console.watch = function(oObj, sProp) {
sPrivateProp = "$_"+sProp+"_$"; // to minimize the name clash risk
oObj[sPrivateProp] = oObj[sProp];
// overwrite with accessor
Object.defineProperty(oObj, sProp, {
get: function () {
return oObj[sPrivateProp];
},
set: function (value) {
//console.log("setting " + sProp + " to " + value);
debugger; // sets breakpoint
oObj[sPrivateProp] = value;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment