1,标识符创建方式 (ES5)
var obj = {}
obj.name = "张三"
obj.age = 23
2,属性名表达式创建方式
var obj = {}
var prop = "name"
obj[prop] = "张三"
obj["a" + "ge"] = 23
3,字面量方式创建(ES6)
var obj = {
name:"张三",
age:23
}
4,属性名表达式创建与字面量创建结合
var prop = "name"
var obj = {
[prop]:"张三",
["a" + "ge"]:23
}
5,通过Object.assign函数创建(ES6)
var obj = Object.assign({},{
name:"张三",
age:23
})
6,通过Object.create函数创建
var obj = Object.create({
name:"张三",
age:23
})