Home / Companies / Snyk / Blog / Post Details
Content Deep Dive

Using ES2015 Proxy for fun and profit

Blog post from Snyk

Post Details
Company
Date Published
Author
Alon Niv
Word Count
1,147
Language
English
Hacker News Points
2
Summary

ES2015 Proxy` allows developers to trap and manipulate property access, setting, has, and deleteProperty events on objects in a controlled manner, providing useful applications for testing, mocking, and monkeypatching, as well as abstractions over complicated concepts. A package `snykwire` is created to safely require modules by limiting their access to specific modules, utilizing the `Proxy` constructor with two parameters: `target` (the object being proxied) and a handler object containing spec for traps to handle. The `get`, `set`, `has`, and `deleteProperty` traps can be used to intercept and control property access, allowing developers to implement features like blacklisting modules and preventing corrupting of the module cache.