对象字面量中可以使用中括号作为属性,表示属性也能是一个变量
- 在对象字面量中可以使用中括号作为属性,表示属性也能是一个变量了。
-
const name = 'Jane';
-
const age = 20
-
-
const person = {
-
[
-
[
-
}
在ant-design的源码实现中,就大量使用了这种方式来拼接当前元素的className,例如:
-
let alertCls = classNames(prefixCls, { -
[`${prefixCls}-${type}`]: true, -
[`${prefixCls}-close`]: !this.state.closing, -
[`${prefixCls}-with-description`]: !!description, -
[`${prefixCls}-no-icon`]: !showIcon, -
[`${prefixCls}-banner`]: !!banner, -

浙公网安备 33010602011771号