123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- </head>
- <body>
- <script>
- /**
- * ES6提供了class(类)的概念;
- * 通过class定义关键字,可以是定义类
- * class 定义类
- * constructor 定义构造函数初始化
- * extends 继承父类
- * super 调用父级构造函数方法
- * static 定义静态的方法和属性
- */
- // class定义类
- class Phone {
- // 构造函数
- constructor(color,rain,holiday) {
- this.color = color;
- this.rain = rain;
- this.holiday = holiday;
- }
- // 类的方法
- call() {
- console.log("打电话");
- }
- green() {
- console.log("这是绿色")
- }
- }
- //es6的继承
- class newPhone extends Phone {
- constructor(color,rain,holiday,book,vase){
- super(color,rain,holiday);
- this.book = book;
- this.vase = vase;
- }
- music() {
- console.log("音乐");
- }
- static end() {
- console.log("结束");
- }
- }
- var a1 = new Phone('红色','晴天','过年');
- console.log(a1);
- var a2 = new newPhone('12','23','34','掘金','花瓶');
- console.log(a2,'a2');
- a2.call();
- a2.music();
- newPhone.end();
- </script>
- </body>
- </html>
|