> Because NoSuchProperty is meant to be inserted just before
Object.prototype

I miss this constrain, wouldn't have bothered with the loop otherwise.

Regards


On Sun, Jun 15, 2014 at 11:27 AM, Brendan Eich <bren...@mozilla.org> wrote:

> Andrea Giammarchi wrote:
>
>> In such case the only concern would be why `Object.prototype` is
>> considered but not inherited properties too.
>>
>
> Because NoSuchProperty is meant to be inserted just before
> Object.prototype, avoiding that loop.
>
> What's more, the loop is unnecessary:
>
>
> var NoSuchProperty = Proxy({}, {
>   get: function(target, name, receiver) {
>     while (target = Object.getPrototypeOf(target)) {
>       if (name in target) {
>         return Reflect.get(target, name, receiver);
>       }
>     }
>     throw new TypeError(name + " is not a defined property");
>   }
> });
>
>
> If NoSuchProperty is inserted just before Object.prototype on a chain of
> ordinary objects, its get handler won't be invoked until no such property
> is indeed found along the path from the original target to NoSuchProperty.
> Therefore all iterations but the last (where target is Object.prototype)
> are redundant.
>
> /be
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to