Object.getOwnPropertyDescriptors(O) ? // plural

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Mar 4 10:11:48 PST 2014


I mixed up ... sorry, let me recap:

   1. `Object.getOwnPropertyNames(O)` list of `properties` and
   `Object.getOwnPropertySymbols(O)` list of `Symbols` can be both used, per
   each item of each list, with `Object.getOwnPropertyDescriptor(O,
   propertyOrSymbol)`
   2. `Object.getOwnPropertyDescriptor(O, propertyOrSymbol)` accepts, as
   second argument, only as a `property` name or a `Symbol`, otherwise it
   throws [as specified here](
   https://people.mozilla.org/~jorendorff/es6-draft.html#sec-topropertykey)
   3. accordingly, the most meaningful collection as `Object` of
   descriptors the proposed plural `Object.getOwnPropertyDescriptors(O)`
   should return is a collection that includes descriptors for both
   `properties` and `Symbols`

I hope this makes sense.
Thanks again Rick for, at least, trying and helping out with this.

Cheers


On Tue, Mar 4, 2014 at 9:48 AM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> yes, because `Object.getOwnPropertyDescriptor(O, k)` accepts both
> `propertyName` and `Symbol` as second argument. The plural, and to be
> consistent with the shallowCopy example, should return a list of both.
>
> This is also because all descriptors returned by
> `Object.getOwnPropertySymbols` can be used same way
> `Object.getOwnPropertyNames` ... so, unless `Object.defineProperty(O, k,
> d)` does not accept `k` as `Symbol` (basically breaking this proposal via
> `Object.create`) I don't see why the plural version should not return
> descriptors for both kind of properties.
>
> My 2 cents
>
>
> On Tue, Mar 4, 2014 at 9:38 AM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
>> Question: should the returned array include property descriptors for
>> properties whose key is a symbol?
>>
>> Rick
>>
>>
>>
>> On Tue, Mar 4, 2014 at 12:34 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>>
>>>
>>>
>>>
>>> On Tue, Mar 4, 2014 at 12:30 PM, Andrea Giammarchi <
>>> andrea.giammarchi at gmail.com> wrote:
>>>
>>>>  Apparently this triggered an @rwaldron which seems to be
>>>> super-effective
>>>>
>>>> In agenda for April's meeting.
>>>>
>>>
>>> Yep: https://github.com/tc39/agendas/blob/master/2014/04.md
>>>
>>> Going to try, but it's so late in the game that I really can't promise
>>> anything--I think it's simple enough that we can get away with it. I will
>>> write up a proposed normative spec (likely based on Andrea's work) before I
>>> present, I've found that's a pretty powerful way to make a case for late
>>> additions ;)
>>>
>>>
>>> Rick
>>>
>>>
>>>>
>>>> Thanks
>>>>
>>>> Sent from my Windows Phone
>>>>  ------------------------------
>>>> From: C. Scott Ananian <cscott at cscott.net>
>>>> Sent: 3/4/2014 6:16
>>>> To: Andrea Giammarchi <andrea.giammarchi at gmail.com>
>>>> Cc: es-discuss at mozilla.org list <es-discuss at mozilla.org>
>>>> Subject: Re: Object.getOwnPropertyDescriptors(O) ? // plural
>>>>
>>>> Have you filed a bugzilla ticket for this? That seems the best way to
>>>> ensure it will get discussed at the next TC39 meeting and resolved one way
>>>> or the other.
>>>>   --scott
>>>> On Mar 3, 2014 8:44 PM, "Andrea Giammarchi" <
>>>> andrea.giammarchi at gmail.com> wrote:
>>>>
>>>>> up ?
>>>>>
>>>>>
>>>>> On Sun, Mar 2, 2014 at 5:43 PM, Andrea Giammarchi <
>>>>> andrea.giammarchi at gmail.com> wrote:
>>>>>
>>>>>> Brandon I take your answer as +1, thanks.
>>>>>>
>>>>>> I've also "gisted" a possible/basic polyfill here:
>>>>>> https://gist.github.com/WebReflection/9317065
>>>>>>
>>>>>> Cheers
>>>>>>
>>>>>>
>>>>>> On Sun, Mar 2, 2014 at 5:16 PM, Andrea Giammarchi <
>>>>>> andrea.giammarchi at gmail.com> wrote:
>>>>>>
>>>>>>> actually, since `Object.getOwnPropertyDescriptor` accepts `Symbols`
>>>>>>> too as second argument, the equivalent with current ES6 would be even more
>>>>>>> prolix than that
>>>>>>>
>>>>>>> ```javascript
>>>>>>>
>>>>>>> var shallowCopy = Object.create(
>>>>>>>   Object.getPrototypeOf(originalObject),
>>>>>>>    Object.getOwnPropertyNames(originalObject).concat(
>>>>>>>   Object.getOwnPropertySymbols(originalObject)
>>>>>>>   ).reduce(function (descriptors, name) {
>>>>>>>     descriptors[name] = Object.getOwnPropertyDescriptor(
>>>>>>>       originalObject, name
>>>>>>>     );
>>>>>>>     return descriptors;
>>>>>>>   }, {})
>>>>>>> );
>>>>>>>
>>>>>>> ```
>>>>>>>
>>>>>>> assuming Symbols will be definable through descriptors ... all this
>>>>>>> VS
>>>>>>>
>>>>>>> ```javascript
>>>>>>> var shallowCopy = Object.create(
>>>>>>>   Object.getPrototypeOf(originalObject),
>>>>>>>   Object.getOwnPropertyDescriptors(originalObject)
>>>>>>> );
>>>>>>> ```
>>>>>>>
>>>>>>> which I believe is a win.
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>>
>>>>>>> On Sun, 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
>>>>>
>>>>>
>>>> _______________________________________________
>>>> 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/20140304/67aa17ec/attachment-0001.html>


More information about the es-discuss mailing list