Proxy and Reflect in Javascript | Part 2

Aniket Jha
Nov 1, 2020

--

In the previous post, we discussed Proxy in detail. In this post, we will build upon that knowledge and learn some more.

Proxy and Reflect in Javascript

Reflect helps in the creation of Proxy and somewhat allow us to play with internal methods [[Get]] and [[Set]]. Below are some reflect methods:

Some Reflect methods

Let us look at a code example:

Reflect Introduction | Code

Reflect allow us to call operators as functions also there is a reflect method for any proxy traps having the same name and arguments.

Reflect Get and Set methods | Code

The Reflect methods work nicely with proxy to ensure that traps output and what we expected is the same. Following is an example:

Proxy getter gotcha | Code

We saw an example of how Reflect is useful for dealing with this Proxy gotcha. I always writereturn Reflect.get(…arguments);😎. Reflect is awesome to enhance proxy and use it correctly. More on proxy on MDN.
Stay tuned for more articles.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Aniket Jha
Aniket Jha

No responses yet

Write a response