DEV Community

Cover image for Proxy Pattern
Tanoy Basak
Tanoy Basak

Posted on

Proxy Pattern

Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

Let’s create a person object, that represents John Doe.

Image description

Now lets analyze an interview question :

𝗛𝗼𝘄 𝗰𝗮𝗻 𝗶 𝘀𝘁𝗼𝗽 𝘀𝗼𝗺𝗲𝗼𝗻𝗲 𝘁𝗼 𝗰𝗵𝗮𝗻𝗴𝗲 𝘁𝗵𝗲 𝗶𝗱 𝗶𝗻 𝘁𝗵𝗲 𝘂𝘀𝗲𝗿 𝗼𝗯𝗷𝗲𝗰𝘁 ?

To freeze the id property in a JavaScript object using a Proxy, you can define a Proxy handler that prevents the id property from being modified. Here's how you can do it :

Image description

Keep Exploring JS ❤

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay