Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 12, 2022 02:16 am GMT

Prototype and Inheritance

Blog Goals:

  1. How inheritance makes coding efficient
  2. How do we achieve Inheritance in Js
  3. Object.create() method
  4. Everything in Js is object
  5. Prototype chain
  6. Prototype method available on the constructor function
  7. Difference between proto and prototype
  8. Creating your own array library

What is a prototype?

  • A blueprint
  • An original object from which a new object is created.

What is inheritance?

  • In simple terms, inheritance is the concept of one thing gaining the properties or behaviors of something else.

  • To say A inherits from B, is saying that A is a type of B.

-a Bird inherits from an Animal because a Bird is a type of Animal it has characteristics of every other animal, but other features as well.

Why Inheritance?

  • It allows us to borrow properties and function methods of one object on another object. ( Inheritance )
  • more reusable codeHow to use Prototypal Inheritance in Js?

There are two ways.

1. Object.create()2. Constructor functions

additional resources:
https://javascript.info/prototype-inheritance
master the js

Thank you for reading :))

sleeping at 12AM and wake up at 5AM can make you productive in life than any other random schedule

If you like my blog, you can connect with me on LinkedIn & can follow me on Twitter & can checkout my Hashnode blog


Original Link: https://dev.to/avinashvagh/prototype-and-inheritance-19mp

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To