Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 9, 2023 16:00
Show Gist options
  • Save suhailgupta03/974dcafbfb32a31e58d7ee5605c82762 to your computer and use it in GitHub Desktop.
Save suhailgupta03/974dcafbfb32a31e58d7ee5605c82762 to your computer and use it in GitHub Desktop.
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