简化对象
let x = 3; let y = 5; //普通写法 let obj = { x:x, y:y, getXy:function(){ return this.x+this.y; } } //ES6写法 let obj = { x, y, getXy(){ return this.x+this.y; } } console.log(obj,obj.getXy);
控制台打印效果
let x = 3; let y = 5; //普通写法 let obj = { x:x, y:y, getXy:function(){ return this.x+this.y; } } //ES6写法 let obj = { x, y, getXy(){ return this.x+this.y; } } console.log(obj,obj.getXy);
控制台打印效果