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.
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 :
Keep Exploring JS ❤
Top comments (0)