Closed odv closed 4 years ago
We cannot reassign a constant variable.
But, if the variable was defined with 'let' instead of 'const', I would do something like this :
user = new Proxy(user, {
get(target, prop) {
if(prop in target) {
return `Property firstName has been read. \n ${target[prop]}`;
} else {
return 'Property you are looking for does not exist.';
}
}
});
const user = { firstName: 'John', lastName: 'Doe', email: 'john.doe@example.com', }