let text, value;
if (typeof f == 'string') {
text = value = f;
} else {
let {
text, value
} = f;
}
这样做会创建两个新的变量(来自于else
),但如果我这样写:
let text, value;
if (typeof f == 'string') {
text = value = f;
} else {
{
text, value
} = f;
}
我收到了一个语法错误。这里最好的解决方法是什么?
const {text, value} = (typeof f === 'string') ? {text: f, value: f} : f;
- loganfsmyth