My ECMAScript 7 wishlist
Brendan Eich
brendan at mozilla.org
Sun Jun 15 11:27:35 PDT 2014
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
More information about the es-discuss
mailing list