繼承的相關概念
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(){}
}