Skip to content

Instantly share code, notes, and snippets.

@viswesh
Created September 21, 2017 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viswesh/679dfbd38afd31334250ce9c176a67cb to your computer and use it in GitHub Desktop.
Save viswesh/679dfbd38afd31334250ce9c176a67cb to your computer and use it in GitHub Desktop.
Sample code for demonstrating Proxy and Reflect usage.
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