getPropertyDescriptor

Tom Van Cutsem tomvc.be at gmail.com
Tue Mar 12 12:03:51 PDT 2013


Hi Erik,

Yes, the proposal you're looking for is <
http://wiki.ecmascript.org/doku.php?id=harmony:extended_object_api>.

Adding this function to ES6 used to make even more sense since the spec
internally used [[GetPropertyDescriptor]], which got exposed in the old
Proxy API. With the internal MOP refactoring, and the shift to direct
proxies, this method is no longer needed internally or in the Proxy API.

That's not to say that it can still be a useful general-purpose reflection
function.

If we do add it, I agree the reflect module is the proper place for it.

Cheers,
Tom

2013/3/12 Erik Arvidsson <erik.arvidsson at gmail.com>

> I thought we talked about adding a function like getOwnPropertyDescriptor
> that walks the prototype chain. This is a common function and I have seen a
> lot of people polyfill this as Object.getPropertyDescriptor.
>
> Can we add @reflect getPropertyDescriptor that would work something like?
>
> export function getPropertyDescriptor(object, name) {
>   if (Object(object) !== object)
>     throw new TypeError();
>   return getPropertyDescriptorInternal(object, name);
> }
>
> function getPropertyDescriptorInternal(object, name) {
>   if (object === null)
>     return undefined;
>   var descr = Object.getOwnPropertyDescriptor(object, name);
>   if (descr)
>     return descr;
>   return getPropertyDescriptorInternal(Object.getPrototypeOf(object),
> name);
> }
>
> --
> erik
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130312/67eb4cae/attachment.html>


More information about the es-discuss mailing list