wangbinze / Daily---3and1

0 stars 0 forks source link

❤️❤️❤️Question024 -JavaScript、谈谈对js中对象的理解,从属性角度出发 #24

Open wangbinze opened 3 years ago

wangbinze commented 3 years ago

题目:谈谈对js中对象的理解,从属性角度出发

wangbinze commented 3 years ago

ECMA-262将对象定义为一组属性的无序集合。这意味着对象就是一组没有特点顺序的值。

理解对象

两种方式创建对象:

let person = new Object(); 
person.name = "Nicholas"; 
person.age = 29; 
person.job = "Software Engineer"; 
person.sayName = function() { 
  console.log(this.name); 
};
let person = { 
  name: "Nicholas", 
  age: 29, 
  job: "Software Engineer", 
  sayName() { 
    console.log(this.name); 
  } 
};

属性的类型

属性分为两种:数据属性和访问器属性