ES6计算(动态)属性名称 [英] ES6 Computed (dynamic) property names
本文介绍了ES6计算(动态)属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读此说明,以便更好地理解ES6 .
I am reading this explanation in order to get a better understanding of ES6.
在增强对象文字方面,它是作为示例代码给出的:
In the bit about Enhanced Object Literals, this is given as example code:
var obj = {
... (removed as not relevant) ...
// Computed (dynamic) property names
[ 'prop_' + (() => 42)() ]: 42
};
除了最后一句话,我了解发生了什么
I understand what is happening except for the last sentence
我明白了
: 42
是要赋予属性的值(数字),并且是
Is the value (Number) that will be given to the property, and that
[ 'prop_' + ... ]
是以字符串 prop _ 开头的动态变量名.
Is a dynamic variable name that starts with the string prop_.
但是,这是什么意思呢?
However, what does this mean/do?
(() => 42)()
推荐答案
(() => 42)()
是使用
查看全文