What do square brackets around a property name in

2019-01-01 12:06发布

问题:

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 %>\']
    }
  }
}

the

[]:[]

it works, I just have not used it or seen it before.

回答1:

Only recently with ES6. They are called \"computed property names\"

From MDN:

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.