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)