????????????繼承?經(jīng)典繼承/混合繼承?/組合式繼承????
????????????一、
????????????當(dāng)B構(gòu)造函數(shù)繼承A構(gòu)造函數(shù)的時(shí)候,
????????????在B構(gòu)造函數(shù)中?借用父構(gòu)造函數(shù)繼承父構(gòu)造函數(shù)的屬性??代碼:A.call(this,參數(shù))
????????????二、
????????????通過(guò)?B構(gòu)造函數(shù)的.prototype.方法名=A構(gòu)造函數(shù).prototype.方法名?來(lái)繼承原型上的方法
????????????原型:prototype?
????????????在構(gòu)造函數(shù)的原型上,添加一個(gè)方法,
????????????通過(guò)這個(gè)構(gòu)造函數(shù)創(chuàng)建出來(lái)的對(duì)象,都共用原型上的方法?(一個(gè)say方)
????????function?A(name,age){
????????????this.name?=?name.slice(0,1);
????????????this.age?=?age;
????????}
????????//?讓所有?用A構(gòu)造函數(shù)創(chuàng)建出來(lái)的對(duì)象?都共用原型上的方法?(一個(gè)say方)???原型:
????????A.prototype.say?=function(){
????????????console.log(this.name)
????????}
????????//?var?a1?=?new?A('s',1)
????????//?var?a2?=?new?A('s2',1)
????????//?a1.say?==?a2.say
????????function?B(name,age,gender){
????????????var?gender?=?gender;
????????????//??借用父構(gòu)造函數(shù)???繼承父構(gòu)造函數(shù)的屬性
????????????A.call(this,name,age);??
????????}
????????B.prototype.say?=?A.prototype.say;
????????var?b?=?new?B('邢三',20,'男');
????????b.say();??//?