Using Traps

Learn how to create traps and use traps to alter the behavior during calls.

Creating a trap to spy

The dummy proxy we created in the previous lesson has no traps in its handler. For each method that’s available on Reflect, we can optionally create a trap in the handler. To create a trap to be used when reading an object’s property, add a get() function to the handler.

Arguments in track function

The trap function for get() takes three arguments:

  • target: This is the same as the first argument we passed to the constructor of Proxy.
  • propertyName: This is the property we are trying to
...
Access this course and 1400+ top-rated courses and projects.