First things first: The official definition of Proxy from MDN is:

“The _Proxy_ object enables you to create a proxy for another object, which can intercept and redefine fundamental operations for that object.”

Now, before going in to dig deeper, let’s first discuss some real-life examples so that at the end, we can have better clarity about Proxy_. _This is how bitfish explained it in his article.

As human beings, we have a lot of things to do in our day-to-day life, such as reading emails, receiving a delivery, etc. Sometimes, we may feel a little anxious because of a lot of extra and unnecessary tasks — like there are a lot of spam emails and it takes some effort and time to get rid of them, or the delivery received may contain bombs planted by terrorists, threatening our security (just a possibility).

That’s where you want someone to protect you from these kinds of threats: a loyal housekeeper. We need someone who does something extra for us to protect what we’re doing.

Now, let’s back to basics — JavaScript. We know that we can extend JavaScript to use features provided by the object-oriented programming paradigm such as encapsulation, abstraction, classes, objects, and so on. We can say that every JavaScript developer uses objects and it’s pretty common to save some info in objects.

But when we do so (use objects), our code becomes less secure. Because JavaScript objects always run naked and you can do anything with them.

So, to tackle this problem, a new feature called Proxy was introduced in ECMAScript 2015, commonly known as ES6. With Proxy, we can find a loyal housekeeper for the object and help us enhance the original functions of the object.

What Is a JavaScript Proxy Object?

_“A JavaScript Proxy is an object that wraps another object (target) and intercepts the fundamental operations of the target object.” — _Javascript Tutorial

For a person, we might have operations like reading mail, picking up delivery, etc., and the housekeeper can do that for us. For an object, the fundamental operations can be the property lookup, assignment, enumeration, and function invocations, etc., which can also be enhanced by the proxy object.

Image for post

#front-end-development #javascript #nodejs #web-development #programming #c++

Everything You Should Know About JavaScript Proxy
1.20 GEEK