let text, value;
if (typeof f == 'string') {
text = value = f;
} else {
let {
text, value
} = f;
}
這樣做創建了兩個新的瓦爾(從else
),但是如果我把它寫像這樣:ES6解構,動態分配
let text, value;
if (typeof f == 'string') {
text = value = f;
} else {
{
text, value
} = f;
}
我收到一個語法錯誤。這裏最好的方法是什麼?
另外'常量{文本,值} =(typeof運算˚F=== '字符串') ? {text:f,value:f}:f;' – loganfsmyth