Created
August 9, 2023 16:00
-
-
Save suhailgupta03/974dcafbfb32a31e58d7ee5605c82762 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Animal() { | |
this.walk = function() { | |
console.log("I'm walking") | |
} | |
this.legs = function() { | |
console.log("I have 4 legs") | |
} | |
} | |
function Herbivore() { | |
this.eat = function() { | |
console.log("I eat only plants") | |
} | |
} | |
// Whenever we create objects using new | |
// the object will have the prototype | |
Herbivore.prototype = new Animal() | |
const rabbit = new Herbivore() | |
rabbit.walk() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment