1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| let name = 'jack'; let sex = 'man';
let obj1 = { name:name, sex:sex, getName:function(){ return this.name; } }
let obj2={ name, sex, getName(){ return this.name; } }
console.log(obj1,obj1.getName()); console.log(obj2,obj2.getName());
|