面向对象原型继承
类:模板
对象:具体的实例
在javascript中类与模板用到了极致
原型:
var student={
name:'caofeng',
run:function (){
console.log(this.name+"run.....");
}
};
var xiaoming={
name:'xiaoming'
};
//小明的原型是student
xiaoming._proto_=student;
class 继承
class关键字实在es6引入的
定义一个类,属性和方法
class student{
constructor(name) {
this.name=name;
}
hello(){
alert('hello');
}
}
let xaioming=new student("xiaoming");
继承
class student{
constructor(name) {
this.name=name;
}
hello(){
alert('hello');
}
}
class xaiostudent extends student{
constructor(name,grade) {
super(name);
this.grade=grade;
}
run(){
alert(this.name+"删除跑路");
}
}
let xaioming=new student("xiaoming");
let xioahong=new xaiostudent("xiaohong",1);