Hacker News new | ask | show | jobs
by kevincennis 2960 days ago
Proxies can also be really helpful for unit tests.

Obviously you have things like sinon for stubbing out methods, but they do have to modify the original object, which I don’t think anybody loves.

But you can also wrap your object in a Proxy with handlers that stub certain methods.

You can also use proxies to implement validation and observability on objects. Here’s a very minimal example of a sort of Backbone-esque Model class with proxies: https://gist.github.com/kevincennis/25ba31b2e9f9c8b7a34047ba...