TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Follow publication

Member-only story

Javascript — Proxy

Deepak Gupta
TDS Archive
Published in
3 min readMay 5, 2018

Before going into why this is important, let's understand what is it. If you already know, feel free to skip a few paragraphs.

Proxy are magic methods

Proxy is an object in javascript which wraps an object or a function and monitors it via something called target. Irrespective of the wrapped object or function existence. Proxy are similar to meta programming in other languages.

There are 3 key terms we need to understand before we proceed:

  1. Targets: Object or Function to be proxied.
  2. Handler: The function that does something on Object or Function that is proxied.
  3. Traps: These are some functions used to work on targets. Click here to read more about traps.

Below is how we defined it

We use Proxy Class from ES6, the arguments, the target is the wrap object and handler will be the function used to do some action on target using traps.

Below is a simple example of its usage

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Deepak Gupta
Deepak Gupta

Written by Deepak Gupta

COO @Steer Protocol| Write about Blockchain & Javascript | Take it easy

Responses (5)