es6 class对象继承

class对象继承

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>class对象继承</title>

</head>
<body>
<div id="ad">

</div>
<div></div>

<script>

    //ES6
    class Phone{
        static phoneName = "手机";
        constructor(brand,price){
            this.brand = brand;
            this.price = price;
        }
        //方法
        static call(name){
            return '打电话给' + name;
        }
    }

    //智能手机

    class SmartPhone extends Phone{

        constructor(brand,price,color){
            super(brand,price);
            this.color = color;
        }
        static call(name){
            return '子类:打电话给' + name;
        }
        //方法
        static photo(type){
            return '拍照' + type;
        }
    }

    let apple = new SmartPhone('苹果',8999,'red');
    console.log(apple);
    console.log(SmartPhone.call('小花'));


</script>
</body>
</html>
posted @ 2021-06-21 12:41  胡勇健  阅读(51)  评论(0)    收藏  举报