es5-class

1. 通过class定义类/实现类的继承
2. 在类中通过constructor定义构造方法
3. 通过new来创建类的实例
4. 通过extends来实现类的继承
5. 通过super调用父类的构造方法
6. 重写从父类中继承的一般方法

<script>
    class Person{
        constructor(name,age){
            this.name=name;
            this.age=age;
        }
        showName(){
            console.log(this.name,this.age)
        }
    }
 //   let person=new Person('kobe',39);
  //  console.log(person,person.showName());//类一般对象方法打印不出来
class strPerson extends Person{
     constructor(name,age,salary){
         super(name,age)
         this.salary=salary;
     }
     showName(){//在子类中定义方法
         console.log(this.name,this.age,this.salary);
     }
}
    let str=new strPerson('weide',38,560000);
    console.log(str);
    str.showName();

    

 

posted @ 2019-12-09 17:26  distant-遥远  阅读(178)  评论(0编辑  收藏  举报