多态:
function makeSound2(animal) {
animal.sound()
}
function Dog2() {}
Dog2.prototype.sound = function () {
console.log("汪汪汪")
}
function Cat2() {}
Cat2.prototype.sound = function () {
console.log("喵喵喵")
}
function Wolf2() {}
Wolf2.prototype.sound = function () {
console.log("嗷嗷")
}
makeSound2(new Dog2())
makeSound2(new Cat2())
网友评论