ES6面向对象
[TOC]
class Person{
constructor(name,age){
this.name = name;
this.age = age;
}
showName(){
console.log(this.name);
}
showAge(){
console.log(this.age);
}
}
let p = new Person("maid",14);
p.showName();
p.showAge();
继承:
class Worker extends Person{
constructor(name,age,job){
super(name,age);
this.job = job;
}
showJob(){
console.log(this.job);
}
}
let w = new Worker("maid",14,"小萝莉");
w.showJob()