类的继承
class Person {
constructor({ name }) {
this.name = name;
}
drive() {
return "人可以看见心";
}
}
const xiaoming = new Person({ name: "张三" });
console.log(xiaoming.name);
console.log(xiaoming.drive());
let a = {
name() { return "a的名字" }
}
let b = {
name: function() { return "b的名字" }
}
console.log(a.name());
console.log(b.name());
class Person {
constructor(option) {
this.title = option.title
}
drive() {
return "这就是人"
}
}
class Man extends Person { //它继承Person
constructor(option) {
super(option); //继承Person的属性
this.color = option.color
}
}
const man = new Man({ color: "red", title: "名人" });
console.log(man.color);
console.log(man.title);
console.log(man.drive());