Skip to content

Instantly share code, notes, and snippets.

@davidgarsan
Created August 14, 2017 10:44
Show Gist options
  • Save davidgarsan/0a6de67de92e2a792ec58491ee4bbae1 to your computer and use it in GitHub Desktop.
Save davidgarsan/0a6de67de92e2a792ec58491ee4bbae1 to your computer and use it in GitHub Desktop.
function spyObjectProperty(obj, key) {
var val = obj[key];
Object.defineProperty(obj, key, {
get() {
return val;
},
set(newVal) {
val = newVal;
console.log(key + ' is now ' + val);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment