面向对象原型继承
- 类:模板
- 对象:具体的实例
var Student ={
name: "流浪者",
age: 3,
run: function(){
console.log(this.name+"run......");
}
};
var xiaoming = {
name:"小明"
};
//原型对象
xiaoming.__proto__=Student;//通过__proto__可调用Student的run()方法
class继承
class
关键字是在ES6引入的
class Student{
constructor(name){
this.name = name;
}
hello(){
alert('hello')
}
}
class XiaoStudent extends Student{
constructor(name,grade) {
super(name);
this.grade = grade;
}
fly() {
alert('I am fly')
}
}
var xiaoming = new Student("xiaoming");
var xiaohong = new XiaoStudent("xiaohong",3);