Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 12, 2016 21:26
Show Gist options
  • Save codecademydev/2acda2836895f5c3e40b069fd0dd02f8 to your computer and use it in GitHub Desktop.
Save codecademydev/2acda2836895f5c3e40b069fd0dd02f8 to your computer and use it in GitHub Desktop.
Codecademy export
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment