I’ve learn the documentation for Proxy and Reflect on MDN however did not perceive a lot. Can anybody please clarify or point out the true world use of those ES6
options.
- One of many good use of proxy I discovered is that we will declare our object values as personal –
const object = {
title: "Rajesh Royal",
Age: 23,
_Sex: "Male"
}
const logger = {
get(goal, property){
if(property.startsWith("_")){
throw new Error(`${property} is a non-public property.`);
}
console.log(`Studying the property ${property}`);
return goal[property];
}
}
const Logger = new Proxy(object, logger);
// now should you attempt to entry the personal property it's going to throw an error
Logger._Sex
Uncaught Error: _Sex is a personal property.
at Object.get (<nameless>:4:19)
at <nameless>:1:8