Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created January 10, 2018 04:50
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 goofmint/3efb717b8604f06dc90ca6f6251e95ea to your computer and use it in GitHub Desktop.
Save goofmint/3efb717b8604f06dc90ca6f6251e95ea to your computer and use it in GitHub Desktop.
const obj = {};
const p = new Proxy(obj, {
get: (target, name) => {
console.log(`(get) target : ${JSON.stringify(target)}, name: ${name}`);
return target[name];
},
set: (target, name, value) => {
console.log(`(set) target : ${JSON.stringify(target)}, name: ${name}`);
target[name] = value;
}
});
p.a = "hello";
p.a
// -> hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment