Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. // the original Animal class and sayName method
  2. function Animal(name, numLegs) {
  3. this.name = name;
  4. this.numLegs = numLegs;
  5. }
  6. Animal.prototype.sayName = function() {
  7. console.log("Hi my name is " + this.name);
  8. };
  9.  
  10. // define a Penguin class
  11. function Penguin() {
  12. this.name = "penguin";
  13. this.numLegs = 2;
  14. }
  15.  
  16. // set its prototype to be a new instance of Animal
  17. var penguin = new Animal("Penguin", 2);
  18.  
  19. penguin.sayName();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement