ES6类的基本语法
例:
class Cat {
constructor(name,age){
this.name = name
this.age = age
}
}
Cat.prototype.eat = function() {
console.log("吃鱼")
}
let cat = new Cat("喵喵",2)
cat.eat()
继承
例:
class User{
constructor(username,password){
this.username = username
this.password = password
}
login(){
console.log("登录")
}
}
class Admin extends User{
deletePerson(){
console.log("删除一个用户")
}
}
let admin = new Admin()
admin.deletePerson()