Object.getOwnPropertyDescriptors(O) ? // plural
Brandon Benvie
bbenvie at mozilla.com
Sun Mar 2 17:14:20 PST 2014
Further rational:
* Symmetry with defineProperty/defineProperties.
* One of the benefits of defineProperties (and create) is that they handle errors such that the failure of any individual property doesn't necessarily fail all the remaining ones. It is, of course, possible for a developer to define their own getOwnPropertyDescriptors to also behave this way, but it's not an obvious concern and is usually overlooked
> On Mar 2, 2014, at 5:01 PM, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote:
>
> I wonder if by any chance this could sneak into ES6 ... we have only singular version here:
> https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.getownpropertydescriptor
>
> **rationale**
> The easiest way to create a shallow copy of a generic object could be:
>
> ```javascript
> var shallowCopy = Object.create(
> Object.getPrototypeOf(originalObject),
> Object.getOwnPropertyDescriptors(originalObject)
> );
> ```
>
> Today what we have to do this instead:
>
> ```javascript
> var shallowCopy = Object.create(
> Object.getPrototypeOf(originalObject),
> Object.getOwnPropertyNames(originalObject).reduce(
> function (descriptors, name) {
> descriptors[name] = Object.getOwnPropertyDescriptor(
> originalObject, name
> );
> return descriptors;
> }, {})
> );
> ```
>
> I see latter pattern as sort of unnecessary overhead that could be also much faster in core and polyfilled in the meanwhile.
>
> Thoughts ?
>
> Cheers
>
>
>
>
> _______________________________________________
> 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/20140302/03d76f2b/attachment-0001.html>
More information about the es-discuss
mailing list