Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // the original Animal class and sayName method
- function Animal(name, numLegs) {
- this.name = name;
- this.numLegs = numLegs;
- }
- Animal.prototype.sayName = function() {
- console.log("Hi my name is " + this.name);
- };
- // define a Penguin class
- function Penguin() {
- this.name = "penguin";
- this.numLegs = 2;
- }
- // set its prototype to be a new instance of Animal
- var penguin = new Animal("Penguin", 2);
- penguin.sayName();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement