对象字面值中的属性名称周围的方括号是什么意思? [英] What do square brackets around a property name in an object literal mean?
本文介绍了对象字面值中的属性名称周围的方括号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在JS写了一段时间,并没有使用这种形式:
I've been writing in JS for a while and have not used this form:
dist: {
files: {
[bpr + 'lib/Monster.min.js']: ['<%= concat.dist.dest %>']
}
}
}
[]:[]
它的作品,我只是没有使用或者看过它。
it works, I just have not used it or seen it before.
推荐答案
只有最近才有ES6。他们称为计算属性名称
Only recently with ES6. They are called "computed property names"
从 MDN :
从ECMAScript 2015开始,对象初始化器语法也是
支持计算的属性名称。这允许您在括号[]
中放入一个表达式
,这将被计算为属性名称。
Starting with ECMAScript 2015, the object initializer syntax also supports computed property names. That allows you to put an expression in brackets
[]
, that will be computed as the property name.
这篇关于对象字面值中的属性名称周围的方括号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文