Class expressions in object initializers.
Blake Regalia
blake.regalia at gmail.com
Thu Jul 14 07:25:44 UTC 2016
A reference to a class is simply a variable. Variables only exist within a
certain scope. When using a variable, its name is essentially irrelevant so
long as you, the developer, understand what it refers to.
If its necessary to distinguish between multiple instances of an object
that were created in response to an unpredictable input, then what you
really need are *properties* (e.g., keys and values, where the keys reflect
the 'dynamic' name), as Bergi points out.
- Blake
On Wed, Jul 13, 2016 at 11:47 PM, Bergi <a.d.bergi at web.de> wrote:
> /#!/JoePea schrieb:
>
>> 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.
>>
>
> If you just want to name a class, there are much easier ways to do that:
>
> let x = class {
> get name() {
> return dynamicName;
> }
> …
> };
>
> or
>
> class x {
> …
> }
> Object.defineProperty(x, "name", { value: dynamicName });
>
> Kind regards,
>
> Bergi
> _______________________________________________
> 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/20160714/5c7bbcf2/attachment.html>
More information about the es-discuss
mailing list