Created
September 9, 2017 18:23
-
-
Save NoMan2000/edb0aa020768cf77420fb1f03902c00f to your computer and use it in GitHub Desktop.
Converting a regular object to an observable
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 convert (obj) { | |
Object.keys(obj).forEach(key => { | |
let internalValue = obj[key] | |
Object.defineProperty(obj, key, { | |
get () { | |
console.log(`getting key "${key}": ${internalValue}`) | |
return internalValue | |
}, | |
set (newValue) { | |
console.log(`setting key "${key}" to: ${newValue}`) | |
internalValue = newValue | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment