ES6 new feature: Object change analysis, es6 new feature object
This article describes the Object changes in the new features of ES6. We will share this with you for your reference. The details are as follows:
Object changes
1. ES6 allows you to write only the attribute name in the object without the attribute value. The attribute value is the variable value corresponding to the attribute name.
var a = 'hi';var obj = {a};console.log(obj); //Object {a: "hi"}
2. Short for methods in the object.
var a = 'hi';var obj = { name: 'ES6', a, sayHi(){ console.log(this.a+' '+this.name); }}obj.sayHi(); //hi ES6
3. ES6 allows the expression to be used as the property name of an object when defining an object literally.
var a = 'b';var obj = { [a]: 'ES6', ['c' + 'd']: 'hi'}console.log(obj); // Object {b: "ES6", cd: "hi"}
4. The method name in the object can be accessed through name.
var a = 'hi';var obj = { name: 'ES6', a, sayHi(){ console.log(this.a+' '+this.name); }}obj.sayHi(); //hi ES6console.log(obj.sayHi.name); //sayHi
5. Object. is ()
It is used to compare whether two values are strictly equal. The difference with = is that Object. is (NaN, NaN) returns true, Object. is (+ 0,-0) returns false.
6. Object. Assign ()
Copies all the enumerated attributes of the source object to the target object.
var obj_source_1 = { a: { a1: 'hi', a2: 'ES6' }, b: 'hello'}var obj_source_2 = { c: 'ES2015',}var result = Object.assign({}, obj_source_1, obj_source_2);console.log(result); //Object {a: Object, b: "hello", c: "ES2015"}
General Usage: Add attributes and methods for objects, clone objects, and merge objects.
I hope this article will help you design the ECMAscript program.