let name = 'test'
let age = 13
let arr = [name, age]
arr >> ["test", 13]
let arr1 = [name+1, age]
arr1 >> ["test1", 13]
let obj = {name: name, age:age}
obj >> {name: "test", age: 13}
let obj1 = {name: name+1, age: age}
obj1 >> {name: "test1", age: 13}
let obj2 = {name+1: name, age: age}
obj2 >> VM426:1 Uncaught SyntaxError: Unexpected token '+'
当使用花括号时,此时的key应该为一个字符串!
ES6中支持的一种方法,使用中括号可以在key值位置直接使用变量
let obj3 = {[name + 1]: name, age: age}
obj3 >> {test1: "test", age: 13}