getPropertyDescriptor

Erik Arvidsson erik.arvidsson at gmail.com
Tue Mar 12 11:07:23 PDT 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130312/6a277f6d/attachment.html>


More information about the es-discuss mailing list