This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

What is the use of Proxy and Reflect in JavaScript?


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
Enter fullscreen mode

Exit fullscreen mode

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?