Class expressions in object initializers.

/#!/JoePea joe at trusktr.io
Thu Jul 14 06:02:26 UTC 2016


A use case could be to dynamically name a class at runtime without `eval`.
`let o = { [name]() {} }` produces a named function inside of `o` (at least
in Chrome) without needing eval, and then we can extract it from the object.

*/#!/*JoePea

On Wed, Jul 13, 2016 at 7:48 PM, Blake Regalia <blake.regalia at gmail.com>
wrote:

> What would be a use case for this?
>
>
>  - Blake
>
> On Wed, Jul 13, 2016 at 7:42 PM, Bergi <a.d.bergi at web.de> wrote:
>
>> /#!/JoePea wrote:
>>
>> Might be nice to be able to do it with classes too:
>>>
>>> ```js
>>> let dynamicName = "foo"
>>> let o = {
>>>   class [dynamicName] { /* ... */ }
>>> }
>>> console.log(o.foo) // logs the class
>>> ​```​
>>>
>>
>> You can already do
>>
>> let dynamicNAme = "foo";
>> let o = {
>>     [dynamicName]: class {
>>>>     }
>> };
>>
>> but I can see absolutely no reason why you'd want to put a class inside
>> an object literal.
>>
>>  Bergi
>>
>> _______________________________________________
>> 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/20160713/adff74f6/attachment.html>


More information about the es-discuss mailing list