es6新增继承

74 阅读1分钟
59         class Phone {
60             // 注意class中的构造方法不是必须的,如果没有也可以
61             constructor(brand, price) {
62                 this.brand = brand;
63                 this.price = price
64             }
65 
66             call() {
67                 console.log('打电话!!');
68             }
69         }
70 
71         // extends 关键字表示继承自哪个类
72         class SmartPhone extends Phone {
73             // 构造方法
74             constructor(brand, price, color) {
75                 // 调用父类的构造方法传参
76                 super(brand, price) // super指代父类的构造方法constructor
77                 this.color = color
78             }
79 
80             playGame() {
81                 console.log('打游戏!!!');
82             }




 let chuizi = new SmartPhone('锤子', '2999', '黑色')
 chuizi.call() // 打电话!!