> ## Content Index
> Fetch the complete content index at: https://blog.hacking.pub/llms.txt
> Use this file to discover other available public pages before exploring further.

# js PropertyName
- URL: https://blog.hacking.pub/2018/04/19/js-zhong-gua-hao/
- Published: 2018-04-19T13:30:07.000Z
- Updated: 2018-04-19T13:30:27.000Z
- Author: chainhelen
- Tags: js, javascript, nodejs, node

本文是一篇大水文，辣眼睛

js中给普通对象（对象字面量，ObjectLiteral）初始化，key值可以是动态的

```
var k = 'you'
var m = {
   [k]: 'are stupid'
} 
console.log(m)
// output 
{you: "are stupid"}

另外注意：
var k = 'you'
var m = {
   ['k']: 'are stupid'
} 
console.log(m)
// output 
{k: "are stupid"}

```

我感觉这里的中括号让我很困惑，求值符号？

我去翻了es5的[bnf](http://es5.github.io/?ref=blog.hacking.pub)，

```
PropertyName :
   IdentifierName
   StringLiteral
   NumericLiteral

//另外
IdentifierName :
    IdentifierStart
    IdentifierName IdentifierPart

```

然而 中括号的token类型是Punctuator，一点关系都没有

百思不得其解

难道是es6？

还真是

![http://es6.ruanyifeng.com/#docs/object](https://blog.hacking.pub/qiniu/js%20PropertyName/1.png)

[es6标准的bff](http://www.ecma-international.org/ecma-262/6.0/index.html?ref=blog.hacking.pub)

![2.png](https://blog.hacking.pub/qiniu/js%20PropertyName/2.png)