The name of a method whose key is a symbol

Andrea Giammarchi andrea.giammarchi at gmail.com
Thu Sep 10 09:17:44 UTC 2015


being a function name I rather wonder if it wouldn't be better to have
`'description'` without square brackets ... to be consistent with the fact
the Symbol has no name.

If that's instead a way specified as such in order to understand that is a
Symbol then I agree, for consistency, it should have square brackets (which
unfortunately when  empty remind me an array)

Regards

On Thu, Sep 10, 2015 at 9:38 AM, Axel Rauschmayer <rauschma at icloud.com>
wrote:

> This is the behavior defined in the spec:
>
> ```js
> const key1 = Symbol('description');
> const key2 = Symbol();
>
> let obj = {
>     [key1]() {},
>     [key2]() {},
> };
> console.log(obj[key1].name); // '[description]'
> console.log(obj[key2].name); // ''
> ```
>
> I’m wondering: if a symbol has no description, wouldn’t it be better to
> give the method the name `'[]'` instead of the empty string?
>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
> rauschma.de
>
>
> _______________________________________________
> 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/20150910/821698cc/attachment-0001.html>


More information about the es-discuss mailing list