ECMA6中的class语法
//ECMA6class语法
class Person{
//class属性添加
constructor(name, sex, age){
this.name = name;
this.sex = sex;
this.age = age;
}
showSelf(){
alert(`我是一个叫${this.name},今年${this.age}岁的${this.sex}孩`);
}
}
var p1 = new Person("blue", "男", 18);
p1.showSelf();
//extends 继承
class Worker extends Person{
constructor(name, sex, age, job){
//1、继承到父一级的属性
super(name, sex, age);
this.job = job;
}
showJob(){
alert("我的工作是" + this.job);
}
}
var w1 = new Worker("小米", "男", 20, "程序员");
w1.showSelf();
w1.showJob();