JavaScript Inheritance

Topics 

  • Inheritance through Prototype 
  • Function constructor and Prototype

Inheritance through Prototype

  • Prototype-based Languages
  • Two different ways for supporting inheritance in programming languages 
    • Scheme #1: Through traditional class hierarchy (Java, C, C++, ...) 
    • Scheme #2: Through prototype (JavaScript) 
  • JavaScript is a prototype-based language 
  • In a prototype-based language, there is no concept of a "class" 
    • Inheritance is provided through prototype, however 
  • In prototype-based language, every object has “prototype” property (the actual name of the “prototype” property is __proto__) that points to “prototype” object 
    • Since the prototype object itself is a JavaScript object, it has its own “prototype” property, which in turn forms “prototype chain”, until it reaches “Object” object, which has null as its prototype

 

Download course content