概念

类就是就是对某一个类具体实例(对象)的抽象 动物是类
对象是类中的具体实例 猫是对象

  1. function Student(name,age){
  2. this.name = name;
  3. this.age = age;
  4. } //Student是类 chen、zhang是对象
  5. var chen = new Student("陈文",18);
  6. var zhang = new Student("张三",18)
  7. /* this指实例化的对象 */
  8. console.log(chen)//{name: "陈文", age: 18}
  9. console.log(zhang)//{name: "张三", age: 18}

读取对象的属性

  1. function Person(name,age){
  2. this.name = name;
  3. this.age = age;
  4. }
  5. var p = new Person("cheng",18);
  6. console.log(p.age)//18