Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  65] [ 7]  / answers: 1 / hits: 33477  / 9 Years ago, mon, november 9, 2015, 12:00:00

I have been experimenting with ES6 classes and am wondering if you can change class names dynamically? For example



class [Some dynamic name] {}; 

More From » class

 Answers
42

There is probably a better solution for whatever you are trying to achieve, but you can assign a class expression to an object:



let classes = {};
classes[someName] = class { ... };


This didn't really change in ES2015: if you want to create a dynamically named binding, you have to use an object or some other mapping instead.


[#64466] Thursday, November 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;