<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sai deepak on Medium]]></title>
        <description><![CDATA[Stories by Sai deepak on Medium]]></description>
        <link>https://medium.com/@saideepak26?source=rss-72efe8d6c885------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yuRfUvdw0ccNA_pzkx-xww.jpeg</url>
            <title>Stories by Sai deepak on Medium</title>
            <link>https://medium.com/@saideepak26?source=rss-72efe8d6c885------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:28:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saideepak26/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Demystifying JavaScript Proxies: Enhancing Object Interactions]]></title>
            <link>https://culture.kissflow.com/demystifying-javascript-proxies-enhancing-object-interactions-370aae99d3d8?source=rss-72efe8d6c885------2</link>
            <guid isPermaLink="false">https://medium.com/p/370aae99d3d8</guid>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[js-proxy-objects]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mdn]]></category>
            <dc:creator><![CDATA[Sai deepak]]></dc:creator>
            <pubDate>Wed, 31 May 2023 10:19:11 GMT</pubDate>
            <atom:updated>2023-05-31T10:19:11.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnnnBUdrw0JJfsIiLugMQw.jpeg" /><figcaption>JS proxy image</figcaption></figure><p>JavaScript’s Proxies in ES6 serve as an intermediary layer, allowing customization of object operations without directly modifying the object. They enable monitoring, control, and added functionality, enhancing programming flexibility.</p><blockquote><strong>What is the need for proxy ?</strong></blockquote><p>Proxies intercept and customize object interactions, ensuring reliable runtime control without modifying the object directly, addressing unintended consequences of direct modifications in complex applications.</p><blockquote><strong>Syntax for defining proxy</strong></blockquote><pre>const myProxy = new Proxy(myObj, {<br>  // Define the behaviour of the proxy here by traps<br>});</pre><p><strong><em>Example</em></strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-xg2ror%3FdevToolsHeight%3D100%26embed%3D1%26file%3Dindex.js%26hideExplorer%3D1%26hideNavigation%3D1%26theme%3Ddark&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-xg2ror%3FdevToolsHeight%3D100%26embed%3D1%26file%3Dindex.js%26hideExplorer%3D1%26hideNavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fsocial-img.staticblitz.com%2Fprojects%2Fjs-xg2ror%2F5526afc6ddb31223ff929a858a4947f1&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb6af73be819b2b449e9ca49e1f68af5/href">https://medium.com/media/fb6af73be819b2b449e9ca49e1f68af5/href</a></iframe><p>Have you noticed in the above code that the <strong>get</strong> method has three parameters</p><p><strong>target:</strong> The target object <strong>i.e.:</strong> myObj.</p><p><strong>key:</strong> The key of the property being accessed (the key here is <strong>name</strong>).</p><p><strong>receiver:</strong> The object that is the receiver of the property access <strong>i.e.:</strong> myObj.</p><p>But not all methods does not have the 3 parameters.</p><p>Okay let me explain you with a small story with some methods defining the proxy</p><blockquote><strong>The story</strong></blockquote><p><em>Meet John, a software developer who has a bank account in XYZ bank with a balance of $10000 who wants to withdraw some money from his bank account. John reaches the bank and finds out that the bank has implemented a new security system. The security system uses a JavaScript Proxy object to handle all bank account related operations.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-vlf4ps%3FdevToolsHeight%3D100%26embed%3D1%26file%3Dindex.js%26hideExplorer%3D1%26hideNavigation%3D1%26theme%3Ddark&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-vlf4ps%3FdevToolsHeight%3D100%26embed%3D1%26file%3Dindex.js%26hideExplorer%3D1%26hideNavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fsocial-img.staticblitz.com%2Fprojects%2Fjs-vlf4ps%2F7386ef0e8caf92b8b6319dd61d18304e&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/270f86e80c59ca0309503e0f19971b98/href">https://medium.com/media/270f86e80c59ca0309503e0f19971b98/href</a></iframe><blockquote><strong>Specifications for defining a proxy</strong></blockquote><p>Well there are some rules that needs to be followed while using or defining a proxy lets see that.</p><p>— A Proxy must always have a target object that it is proxying. This target object can be any JavaScript object, including other Proxy objects.</p><p>— A proxy intercepts user operations, utilizing traps (custom methods) to add custom behavior to the object before modifying the original.</p><p>— <strong>List of traps</strong></p><ul><li><strong>get</strong>: Intercepts property access.</li><li><strong>set</strong>: Intercepts property assignment.</li><li><strong>has</strong>: Intercepts the in operator.</li><li><strong>deleteProperty</strong>: Intercepts property deletion.</li><li><strong>ownKeys</strong>: Intercepts calls to Object.getOwnPropertyNames and Object.getOwnPropertySymbols.</li><li><strong>defineProperty</strong>: Intercepts calls to Object.defineProperty and Object.defineProperties.</li><li><strong>construct</strong>: Intercepts calls to new.</li><li><strong>etc…</strong> and there are many more traps which you can refer</li></ul><p>— By using these traps we can implement many features such as validation, caching, error logging etc…</p><p>— The target object and the proxy object in a proxy definition are separate, meaning changes to one do not automatically impact the other.</p><ul><li>Proxies in JavaScript wrap objects, enabling customization and interception of operations, while maintaining separate control and customization from the original object.</li></ul><pre>const target = { foo: &#39;bar&#39; }; <br>const handler = { get: () =&gt; &#39;from handler&#39; }; <br>const proxy = new Proxy(target, handler); <br>console.log(proxy.foo); // outputs &quot;from handler&quot;<br>console.log(target.foo); // outputs &quot;bar&quot;</pre><p>— Unsupported traps in a Proxy can lead to fallback to default behavior, potentially resulting in errors or unexpected behavior.</p><pre>const target = { foo: &#39;bar&#39; };<br>const handler = {<br>  get: function(target, prop) {<br>    if (prop in target) {<br>      return Reflect.get(target, prop);<br>    }<br>  }<br>};<br>const proxy = new Proxy(target, handler);<br><br>console.log(proxy.foo); // outputs &quot;bar&quot;<br>console.log(proxy.baz); // outputs &quot;undefined&quot;</pre><p>— A Proxy can be revoked using the Proxy.revocable() method, which returns a revocable Proxy that can be revoked using the revoke() method.</p><pre>const obj = {<br>  foo: &#39;hello&#39;,<br>  bar: 123,<br>  baz: true<br>};<br><br>const handler = {<br>  get(target, prop, receiver) {<br>    console.log(`Getting property &quot;${prop}&quot;...`);<br>    return Reflect.get(target, prop, receiver);<br>  }<br>};<br><br>const {proxy, revoke} = Proxy.revocable(obj, handler);<br><br>console.log(proxy.foo); // outputs &quot;Getting property &quot;foo&quot;...&quot; and prints &quot;hello&quot;<br>console.log(proxy.bar); // outputs &quot;Getting property &quot;bar&quot;...&quot; and prints 123<br>console.log(proxy.baz); // outputs &quot;Getting property &quot;baz&quot;...&quot; and prints true<br><br>revoke();<br><br>console.log(proxy.foo); // throws an error, as the proxy has been revoked</pre><blockquote><strong>Advantages</strong></blockquote><ol><li><strong>Customizable behaviour:</strong> Proxies allow you to define custom behaviour for object properties, which gives you a lot of flexibility in how you handle data in your code.</li><li><strong>Security:</strong> Proxies can be used to prevent unauthorised access to certain properties or methods of an object, making your code more secure.</li><li><strong>Performance:</strong> By using Proxies, you can avoid expensive computations until they are actually needed. This can improve the overall performance of your code.</li><li><strong>Debugging:</strong> Proxies can be used to provide better debugging information when an error occurs, as they allow you to track the changes in an object.</li></ol><blockquote><strong>Disadvantages</strong></blockquote><ol><li><strong>Compatibility:</strong> Proxies are not supported in older browsers, which can limit the compatibility of your code.</li><li><strong>Complexity:</strong> Proxies can be difficult to understand and maintain, especially for developers who are not familiar with the concept.</li><li><strong>Performance:</strong> While Proxies can improve performance in some cases, they can also introduce overhead and slow down your code, especially if you use them extensively.</li><li><strong>Potential errors:</strong> If you’re not careful, Proxies can introduce errors into your code, such as infinite loops or unexpected behaviour.</li></ol><blockquote>Conclusion</blockquote><p>In summary, Proxies provide a powerful way to customize object interactions, enhancing flexibility and control. While offering advantages such as customizable behavior and improved security, but they may introduce compatibility limitations and complexity if not used carefully.</p><blockquote>References</blockquote><p>— <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy</a></p><p>— <a href="https://caniuse.com/proxy">https://caniuse.com/proxy</a></p><p>— <a href="https://tc39.es/ecma262/multipage/reflection.html#sec-proxy-objects">https://tc39.es/ecma262/multipage/reflection.html#sec-proxy-objects</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=370aae99d3d8" width="1" height="1" alt=""><hr><p><a href="https://culture.kissflow.com/demystifying-javascript-proxies-enhancing-object-interactions-370aae99d3d8">Demystifying JavaScript Proxies: Enhancing Object Interactions</a> was originally published in <a href="https://culture.kissflow.com/">Kissflow Culture | Explore Our Butterfly Effect</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>