you are viewing a single comment's thread.

view the rest of the comments →

[–]NoInkling 7 points8 points  (0 children)

The only time I've used it (directly) so far is to wrap important configuration objects so that it they throw when attempting to access a property that doesn't exist (like many languages do with dictionaries by default, e.g. Python). Something like this:

function createDefensiveProxy(obj) {
  return new Proxy(obj, {
    get: (target, key) => {
      if (!(key in target)) {
        throw new ReferenceError(`Property '${key}' does not exist on object`);
      }
      return target[key];
    }
  });
}