ES6 class 继承

   class Phone {
                constructor(brand, price) {
                    this.brand = brand
                    this,price = price
                }
                call () {
                    console.log('我可以打电话')
                }
            }
            class SmartPhone extends Phone {
                constructor (brand, price, color, size) {
                    super(brand, price)
                    this.color = color
                    this.size = size
                }
                photo () {
                    console.log('我可以拍照')
                }
                playGame () {
                    console.log('我可以玩游戏')
                }
                call () {
                    console.log('我可以视频通话')
                }
            }
            let xiaomi = new SmartPhone('小米', 7999, '黑色', '5.1')
            xiaomi.call()
            xiaomi.photo()
            xiaomi.playGame()

posted on 2021-01-12 15:35  家有糖果  阅读(35)  评论(0)    收藏  举报

导航