Object Initializer
The list variable name and the state property name share the same name
.
ES5
var name = 'jack';
var user = {
name: name,
};
equivalent to ES6
const name = 'jack';
const user = {
name
}
Obejct Method
ES5
var user = {
getName: function() {
return this.firstName + ' ' + this.lastName;
},
};
ES6
const user = {
getName() {
return this.firstName + ' ' + this.lastName;
},
};
New Object
ES6 new function assign()
let obj1 = { a: 'a' };
let obj2 = Object.assign({}, obj1); // deep clone
Deep Clone
means obj1 and obj2 are indivials, not sharing same things. stackoverflow@dlamblin
Merge
let obj3 = Object.assign(obj1, obj2);
Computed Variable
var searchKey = 'key1';
this.setState({
results: {
...results,
[searchKey]: {hits: updatedHits, page}
},
});