类似 $.ajax({xxx}) new Vue({xxx}) 。。。 有了es6的简单语法,自己也可以封装一个
class Person{
//构造函数
constructor(country){
this.country=country
}
}
class Chinese extends Person{ //继承自Person类
constructor(name){
super("中国") //调用父类构造函数
this.name=name
}
sayHellow(){ //多了一个sayHellow方法
console.log(`我叫${this.name},来自${this.country}`);
}
}
class American extends Person{ //继承自Person类
constructor(obj){ //传进来一个对象
super("America")
this.name=obj.name
}
sayHellow(){
console.log(`My name is ${this.name} from ${this.country}`);
}
}
const chinese = new Chinese("胡歌")//实例化Chinese对象
chinese .sayHellow() //调用实例的sayHellow方法
const american =new American({
name:"Jack"
})
american.sayHellow()