JavaScript 아 날로 그 정책 모드

3317 단어 JavaScript
/**

 *       ,        ;

 */

function FlyInter () {}

FlyInter.prototype.fly = function() {

    throw '      ';

};

/**

 *     fly noway   ;

 */

function FlyNoWays() {}

FlyNoWays.prototype.fly = function() {

    console.log('fly noways');

};

/**

 *     fly with Wings   ;

 */

function FlyWithWings () {}

FlyWithWings.prototype.fly = function() {

    console.log('fly with wings');

};

/**

 *     ;            ;

 */

function Duck() {

    this.flyI = new FlyInter();

}

Duck.prototype.swim = function() {

    console.log('duck can swim');

};

/**

 * fly    flyI   fly  ;

 */

Duck.prototype.fly = function() {

    this.flyI.fly();

};

/**

 * RubberDuck  Duck;          fly  ;

 */

function RubberDuck () {

    this.flyI = new FlyNoWays();

}

RubberDuck.prototype = new Duck();

RubberDuck.prototype.constructor = RubberDuck;

delete RubberDuck.prototype.flyI;



var rDuck = new RubberDuck();

//    Duck  fly()    ;

rDuck.fly();

좋은 웹페이지 즐겨찾기