Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Last active December 28, 2020 15:36
Show Gist options
  • Select an option

  • Save Jagathishrex/d54d112861308d94028d230d212aa0d3 to your computer and use it in GitHub Desktop.

Select an option

Save Jagathishrex/d54d112861308d94028d230d212aa0d3 to your computer and use it in GitHub Desktop.
let target = {
name : "Mia",
age : 28
};
let handler = {
get(targetObject, propertyName) {
if( propertyName in targetObject) {
return `The ${propertyName} is ${targetObject[propertyName]}`;
}
}
};
let proxy = new Proxy(target, handler);
proxy.name; // The name is Mia
proxy.age; // The age is 28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment