Skip navigation

The code below pretty much explains itself. Just follow the comments. You can also run the code snippet in the firefox console tab

// Parent class definition
var Human = function(name, age) { = name;
    this.age = age;

// Child class definition
var Indian = function(name, state){
    if(name) = name;
    this.state = state;

// Extending
Indian.prototype = new Human('raja',22);

// Creating instance of child class with own name property
var tamilian = new Indian('kvk','TN');

// Creating another instance of child class without own property
var cbe_ian = new Indian('','TN');

alert(;  // kvk
alert(tamilian.age);   // 22
alert(tamilian.state); // TN
alert(;   // raja


  1. Shouldn’t be ‘kvk’ and be ‘raja’ ?

  2. Thanks for updating

  3. Good Raja

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: