/**
* 多态思想
*
* 动物都有叫声 不同动物叫声不同
*
* **/
const makeSound = function (animal: any) {
animal.sound()
}
class Dog {
sound() {
console.log('旺旺')
}
}
class Duck {
sound() {
console.log('嘎嘎嘎')
}
}
makeSound( new Dog() )
makeSound( new Duck() )
网友评论