// original classes

function Animal(name, numLegs) {

    this.name = name;

    this.numLegs = numLegs;

    this.isAlive = true;

}

function Penguin(name) {

    this.name = name;

    this.numLegs = 2;

}

function Emperor(name) {

    this.name = name;

    this.saying = "Waddle waddle";

}


// set up the prototype chain

Penguin.prototype = new Animal();

Emperor.prototype = new Penguin();


var myEmperor = new Emperor("Jules");


console.log( myEmperor.saying ); // should print "Waddle waddle"

console.log( myEmperor.numLegs ); // should print 2

console.log( myEmperor.isAlive ); // should print true

'WEB > javascript' 카테고리의 다른 글

[javascript] 정렬하기  (0) 2014.08.01
json 변환  (0) 2014.06.05

+ Recent posts