Created
September 21, 2017 18:35
-
-
Save viswesh/679dfbd38afd31334250ce9c176a67cb to your computer and use it in GitHub Desktop.
Sample code for demonstrating Proxy and Reflect usage.
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 propDefaults(defaults) { | |
const handler = { | |
get (obj, prop) { | |
return Reflect.get(obj, prop) || defaults[prop]; | |
} | |
}; | |
return new Proxy({}, handler); | |
} | |
const palette = propDefaults({color: "yellow"}); | |
console.log(palette.color) //yellow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment