ES6动态类名 [英] ES6 Dynamic class names
本文介绍了ES6动态类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试验ES6类,我想知道你是否可以动态改变类名?例如
I have been experimenting with ES6 classes and am wondering if you can change class names dynamically? For example
class [Some dynamic name] {};
推荐答案
要实现,但你可以为一个对象赋予一个类表达式:
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 { ... };
在ES2015中没有真正改变:如果你想创建一个动态命名的绑定,以使用对象或其他映射。
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.
这篇关于ES6动态类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文