原型式继承-编码练习

//prototype
function  father ( ) {
        this . money  '1000' ;           
}

father . prototype . hasPrice  function ( ) {
        console . log ( this . money ) ;        
}
    
function  son ( ) {
        this . ability  'earn som money' ;
}
  
son . prototype  new  father ( ) ;

son . prototype . hasAbility  =   function ( ) {
        console . log ( this . ability ) ;        
}

var  badson  new  son ( ) ;

badson . hasPrice ( ) ;//1000

badson.hasAbility();//earn some money

原型式继承存在两个问题:1、所有子继承都会共享父继承的属性和方法,这样当改写继承的属性(引用类型)时,所有子继承实例共享;2、子不可向父传参数。

问问:改写父的属性(引用类型),会子的实例都共享,而属性不是引用类型,不会出现共享?

2、

你可能感兴趣的:(原型式继承-编码练习)