Object.getOwnPropertyDescriptor can return just about anything

Jason Orendorff jason.orendorff at gmail.com
Wed Apr 30 09:30:08 PDT 2014


On Tue, Apr 29, 2014 at 7:49 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
> The idea is that a Proxy can define its own property descriptor formats that it exposes to and accepts form user code. vis Object.defineProperty/Object.getOwnPropertyDescriptors.  This includes the possibility of new property attributes and censoring built-in attributes.

New property attributes will be useful in fancy metaprogramming, such
as glue layers binding JS to other languages with different object
models. Proxies already provide plenty of rope for those users without
[[Origin]]. They will of course wish to store property metadata in a
form other than complete descriptor objects, and they can do that
internally. They can even easily provide custom reflection APIs to
expose their custom metadata. But [[GetOwnProperty]]'s job is to make
those special properties intelligible to the rest of JS, and
Object.getOwnPropertyDescriptor's job is to reflect
[[GetOwnProperty]].

> For example, you might define a Proxy that exposes something like a typed array but which did not have any attributes on indexed properties.

Well---all properties have attributes. [[GetOwnProperty]] always
returns a complete Property Descriptor Record, or undefined. The
language relies on it.

In that light, you're saying: "you might define a Proxy that exposes
something like a typed array but for which the reflection APIs don't
work". You might, but why?

-j


More information about the es-discuss mailing list