class的类继承

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
<script>
    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("玩游戏");
        // }
    }
    
    const xiaomi = new SmartPhone('小米',799,'黑色','4.7inch')
    console.log(xiaomi);
</script>
    </body>
</html>

 

 

 

posted @ 2023-02-20 11:34  罗砂  阅读(25)  评论(0)    收藏  举报