继承的相关概念
1.继承使得子类拥有了父类的属性和方法[tu]
2.子类函数构造出的对象具有父类对象的属性和方法
3.注意区分实列属性与继承.继承要隔一层(需要两次以上的原型搜索)[tu]
如:
a=new Array()
a.valueOf()是继承的
a.push()是实例属性
--
类
1.能产生对象的东西(构造函数)就叫类
2.
es5实现继承[土]
functio Human(name){
this.name=name;
}
Human.prototype.run=function(){}
function Man(){
Human.call(this,name)
this.xingbie="nan"
}
Man.prototype.__proto__=Human.prototype //链接原型链,但ie不支持
//代替方法
function f(){}
f.protype=Human.protype
Man.protype=new f()
3.es6类实现继承
class Human{
construtor(name){this.name=name}
run(){console.log('555');return undefined;}//定义在源性上方法
xingbie(){return '男'} //es6在原型上生声明一个非方法属性方式.es5=>xingbie="南"
}
class Man extends Human{ //extends链接原型连=>Man.prototype.__proto__=Human.__proto__
contrutors(name){
super(name) //Human.call(this,name),调用构造函数
this.xingbie="男"
}
fight(){}
}