2
{
hello_en: 'hello world',
'hello_zh-CN': '世界您好',
something: 'nice day',
something_else: 'isn\'t it'
}
被传递给函数
function(data) {
const { hello_en, hello_zh-CN, ...rest } = data
// do some stuff with hello_en and hello_zh-CN
// so some other stuff with rest
}
当然hello_zh-CN
,但对象不是有效的键名。
我无法写
const { hello_en, 'hello_zh-CN', ...rest } = data
为给出了一个错误。
当某个键是字符串时,如何解构对象的属性?
请参阅本[MDN节(https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment #Invalid_JavaScript_identifier_as_a_property_name) –