class介绍初体验

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script>
            class Shouji{
                // 构造方法  名字不能修改
                constructor(brand,price){
                    this.brand = brand
                    this.price = price
                }
                // 方法必须使用该语法,不能使用ES5的对象完整形式
                call(){
                    console.log("我可以打电弧");
                }
            }
            
            let onePlus = new Shouji("蓝狐",999+'元');
            console.log(onePlus);
        </script>
    </body>
</html>

 

 

posted @ 2023-02-20 10:50  罗砂  阅读(19)  评论(0)    收藏  举报