aardio实现封装继承多态
本帖最后由 axuanup 于 2024-2-8 00:19 编辑import console;
//封装
class Animal{
ctor(name) {
this.name = name
}
eat = function() {
..console.log(this.name + " is eating.")
}
}
//继承
class Carnivore{
ctor(name) {
this = ..Animal(name)
}
eat = function() {
..console.log(this.name + " is eating meat.")
}
}
//多态
class Herbivore{
ctor(name) {
this = ..Animal(name)
}
eat = function() {
..console.log(this.name + " is eating plants.")
}
}
var carnivore = Carnivore("Tiger")
var herbivore = Herbivore("Deer")
carnivore.eat()// 输出 "Tiger is eating meat."
herbivore.eat()// 输出 "Deer is eating plants."
console.pause(true);
支持了,学习下
页:
[1]