Created
August 14, 2017 10:44
-
-
Save davidgarsan/0a6de67de92e2a792ec58491ee4bbae1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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