代码示例
class Father { constructor(name,price) { this.name = name; this.price = price; }; call() { console.log("手机可以打电话!"); }; }; class Son extends Father { constructor(name,price,color,size) { super(name,price); this.color = color; this.size = size; }; photo() { console.log("手机可以拍照"); }; call() { console.log("这是子类的函数"); }; }; const xiaomi = new Son("红米K30","4999","荣耀黑","6.7英寸"); console.log(xiaomi); xiaomi.call();
实现效果