【发布时间】:2023-01-13 10:51:21
【问题描述】:
我喜欢传递参数并想用它来返回特定的变量
test1 (type) {
const enable { color: 'blue' }
const disabled { color: 'red' }
return type === 'enable' ? enable : disabled
}
例如,我喜欢将 test1 更改为 test2。 我想这样做是因为我有多种类型,这会使代码变得复杂。 有什么办法可以做到这一点?
test2 (type) {
const enable { color: 'blue' }
const disabled { color: 'red' }
return type
}
【问题讨论】:
-
在变量初始化中需要
=:const enable = {...}
标签: javascript