What is Proxy in Javascript ?

What is Proxy in Javascript ?

Hi Everyone ,

Today let's discuss about Proxy in JavaScript and how we can use them in our code.?

The very first basic question is, What is a Proxy ??

It is a feature offered by JavaScript through which we can access the object through a surrogate.?

How to create a Proxy ?

We can create a Proxy using in-built Proxy Constructor


When a proxy constructor is invoked it expects two arguments, one is the Target Object. In this case, it is a 'scientist', and we need to pass an object as a second argument and let's analyze the second argument further because it makes the proxies more unique and powerful.


It works like a normal object. You can get and set values, like How you do it with a normal object but something else is going on behind the scenes. Let's investigate it.?


In the second argument, we can use methods, which are called Traps, and they are called certain actions are performed on objects.?

?In the above example, we have specified two traps, get and set. Whenever we try to access the property of the object, the get method is implicitly called and the same goes for the set method and we are trying to access a property called invention which is not present in the object , In those places instead of undefined, we can return custom values in those places like shown in the above example

We can also manipulate other traps, like apply and enumerate using the same method.

Uses

We can use a Proxy? to measure performance, logging, validation, and we can also auto-populate the object properties.?

Drawback

Proxies are not fast. If it is overused it will make your application sloppier, so you must test the performance of the code when you use a Proxy.


This is just a gist of the Proxy in JavaScript, let's discuss more about it in future articles.


Thanks for reading ,

Vijay


要查看或添加评论,请登录

Vijayamuralikrishna J的更多文章

  • Closure on Hardware

    Closure on Hardware

    Hello Human, Today, I thought about discussing the concept of closure. Let's start with our usual question: What is a…

  • React-State Management using URL

    React-State Management using URL

    Hi Reader , Today let's look at on how to store the state of our pages in the URL and those can be used to increase the…

  • Infinite Scroll Using Monad

    Infinite Scroll Using Monad

    Hi folks , Today I thought about discussing with you all about a code which was written with a lot of side effects and…

  • Type "any"- useful or useless?

    Type "any"- useful or useless?

    Hi folks , It's been sometime , did not write much lately and today I thought to write about type "any" and it's going…

  • Interface in Typescript

    Interface in Typescript

    Hi Folks , Today let's a take a look at Interface in typescript , from the word interface we can understand that we are…

    1 条评论
  • Types in Typescript

    Types in Typescript

    Hi all , As I said in my last article , will write about Typescript in my coming articles ,This is article belongs to…

  • Typescript- Why we must use it in our JS projects ?

    Typescript- Why we must use it in our JS projects ?

    Hi folks , Today I have decided to discuss about TypeScript with you all , When I started to write my applications with…

  • Recursion - Basic Explanation

    Recursion - Basic Explanation

    Hi folks , Today I thought to write about Recursion, a powerful functional programming concept First, let's see the…

  • Play With Pics - Just a CANVAS

    Play With Pics - Just a CANVAS

    Hi Folks , Today I thought of sharing a simple application with you all , I just made this application to exhibit that,…

  • Scope Of React-Testing

    Scope Of React-Testing

    Hi folks, If you are a React developer then probably you will be writing test cases for your apps using jest and…

社区洞察

其他会员也浏览了