美文网首页
2021-06-21多态性

2021-06-21多态性

作者: 0说 | 来源:发表于2021-06-21 23:10 被阅读0次
     /**
         * 多态思想
         * 
         * 动物都有叫声 不同动物叫声不同
         * 
         * **/ 
        
        const makeSound = function (animal: any) {
          animal.sound()
        }
        class Dog {
          sound() {
            console.log('旺旺')
          }
        }
    
        class Duck {
          sound() {
            console.log('嘎嘎嘎')
          }
        }
    
        makeSound( new Dog() )
        makeSound( new Duck() )
    
    

    相关文章

      网友评论

          本文标题:2021-06-21多态性

          本文链接:https://www.haomeiwen.com/subject/mknuyltx.html