Praveen Singh

Simple Inheritance in Javascript


Simple prototypes based Inheritance in Javascript

JavaScript is an object-oriented language based on prototypes, rather than being class-based. Because of this different basis, it can be less apparent how JavaScript allows you to create hierarchies of objects and to have inheritance of properties and their values

I will try to explain Inheritance by a simple code example in this article

But before i can start, we have to take a usecase, an example of inheritance to begin with

Class Digram for the example

step by step video tutorial


 * Lets define all the Objects(Classes for Java and C++ guys, mind it, there is nothing call Class in Java)
 function Developer(name) { = name;
    this.skill = "no skill";

    this.printSkill = function() {

        console.log("Skill: ", this.skill);


    this.printName = function() {

        console.log("I am : ",;


    this.workOn = function() {

        console.log("Not sure!");



function JavaDeveloper(name) {
    this.skill = "Java"; = name;

    this.workOn = function() {

        console.log("I work on Server side");



function JavaScriptDeveloper(name) {
    this.skill = "Javascript"; = name;

    this.workOn = function() {

        console.log("I work on client side");



function NodeJSDeveloper(name) { = name;

    this.workOn = function() {
        console.log("I work on server side");


 * Inheritance Linking go below
JavaDeveloper.prototype = new Developer();
JavaScriptDeveloper.prototype = new Developer();
NodeJSDeveloper.prototype = new JavaScriptDeveloper();

var developer = new NodeJSDeveloper("praveen");

console.log(developer instanceof Developer);
console.log(developer instanceof NodeJSDeveloper);
console.log(developer instanceof JavaDeveloper);


Javascript prototypes based Inheritance make it powerful and dynamic, but it is not simple to understand and implement like Java or C++

Here language like DOJO jump in and provide inheritance in Java in plain Javascript

Contact Me

If you want to contact me for feedback or suggestion or doubt. You can do so by commenting on Blogger article or in Youtube comments section.

You can also approach me dropping me mail directly at

1 comment:

  1. clear cutttt explanation.. thanks it helps for java lover like me