Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created Jan 10, 2018
Embed
What would you like to do?
class Animal {
constructor() {
this.name = '';
}
setName(name) {
this.name = name;
}
getName() {
return this.name;
}
}
const dog = new Proxy(new Animal, {
get: (target, name) => {
console.log(`(class get) target : ${JSON.stringify(target)}, name: ${name}`);
return target[name];
},
set: (target, name, value) => {
console.log(`(class set) target : ${JSON.stringify(target)}, name: ${name}`);
target[name] = value;
}
});
dog.setName('dog');
console.log(dog.getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment