Skip to content

43 Prototypes

Biswajit Sundara edited this page Aug 19, 2023 · 4 revisions

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

1. Get Started

  • Write this object in chrome browser console and then type user.
  • We will observe the name property comes and a bunch of other properties
const user = {
    name: 'Biswajit'
}
  • Similarly for array const hobbies = ['read','eat','play']
  • We can observe there are methods like length, push, pop when we do hobbies.
  • For function also greet. we can observe call, bind, apply etc are popping up
function greet(){
    console.log('Hello');
}
  • It happens to primitive data types also const username = 'Mark' and then do username.
  • We haven't defined those so how those are getting added to our object/variable/function?
  • It happens due to prototype

2. Prototypes

  • In Javascript if we create an object or instance of a function

Clone this wiki locally