Brendan Eich (2014-06-06T00:52:47.000Z)
Rick Waldron wrote:
>
>     * `Object.preventUndeclaredGet()` - change an object's behavior to
>     throw an error if you try to read from a property that doesn't
>     exist (instead of returning `undefine`).
>
>
> This can be achieved with Proxy right, or is that too cumbersome?

js> var NoSuchProperty = Proxy({}, {
   has: function(target, name) { return true; },
   get: function(target, name, receiver) {
     if (name in Object.prototype) {
       return Object.prototype[name];
     }
     throw new TypeError(name + " is not a defined property");
   }
});
js> var obj = Object.create(NoSuchProperty)
js> obj.foo = 42
42
js> obj.foo
42
js> obj.bar
/tmp/p.js:7:4 TypeError: bar is not a defined property

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140605/a33af298/attachment.html>
domenic at domenicdenicola.com (2014-06-10T19:23:02.125Z)
Rick Waldron wrote:
>
> > - `Object.preventUndeclaredGet()` - change an object's behavior to
> >   throw an error if you try to read from a property that doesn't
>  >  exist (instead of returning `undefine`).
>
>
> This can be achieved with Proxy right, or is that too cumbersome?

```
js> var NoSuchProperty = Proxy({}, {
   has: function(target, name) { return true; },
   get: function(target, name, receiver) {
     if (name in Object.prototype) {
       return Object.prototype[name];
     }
     throw new TypeError(name + " is not a defined property");
   }
});
js> var obj = Object.create(NoSuchProperty)

js> obj.foo = 42

42
js> obj.foo

42
js> obj.bar
/tmp/p.js:7:4 TypeError: bar is not a defined property
```