descriptors and not only own properties gotcha

Andrea Giammarchi andrea.giammarchi at
Wed Dec 17 10:09:12 PST 2014

This is mainly for clarification purpose since I need to handle these
objects in a single place.

Reading descriptors's description:

and reading how descriptors are retrieved:

I wonder if it will ever happen that inherited properties will be just
ignored/dropped and descriptors made safer without being able to set
properties, even by accident, on the `Object.prototype`

### Rationale & Examples
It looks like `getOwnPropertyDescriptor` will always return objects with
own properties, making considered inheritance for descriptor not only an
issue when setting them, but also when reading them.

Object.prototype.get = function () {};
var descriptor = Object.getOwnPropertyDescriptor(
// resultingo into
Object {
  value: function,
  writable: true,
  enumerable: false,
  configurable: true,
  get: function

// note the get is inherited

How can I tell if I should accept a property without passing through `value
in object || object.hasOwnProperty('get')` and similar stuff?

I'd say own properties should have priority but then why are inherited
properties considered at all if these cannot be overwritten without causing
potential problems?

As example, that descriptor that inherits from `Object.prototype` has been
retrieved via native methods, `Object.getOwnPropertyDescriptor`, and it
will **fail** through native methods.

Following an example:

Object.defineProperty(Object.prototype, 'toString', descriptor);
Uncaught TypeError: Invalid property.  A property cannot both have
accessors and be writable or have a value, #<Object>message: "Invalid
property.  A property cannot both have accessors and be writable or have a
value, #<Object>"stack: (...)get stack: function () { [native code] }set
stack: function () { [native code] }__proto__: Error

Thanks for any sort of outcome.

Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list