Skip to content

Instantly share code, notes, and snippets.

@srinivasKandukuri
Last active June 1, 2017 04:04
Show Gist options
  • Select an option

  • Save srinivasKandukuri/35e9aecb4e48259ff919816a743ea21c to your computer and use it in GitHub Desktop.

Select an option

Save srinivasKandukuri/35e9aecb4e48259ff919816a743ea21c to your computer and use it in GitHub Desktop.
Javascript Basic inheritance example
var Human = function(name){
this.name = name;
};
Human.prototype.talk = function(){
return 'this is Human talking';
}
Human.prototype.walk = function(){
return 'I am Human I can walk with legs'
}
var Animal = function (){};
Animal.prototype.talk = function(){
return 'this is Animal talking';
}
function Ben(){
Human.call(this, 'BEN');
Animal.call(this);
}
Ben.prototype.sleep = function(human){
return human.name;
}
Ben.prototype.talk= function(){
return Human.prototype.talk.call(this);
}
Ben.prototype = $.extend({}, Human.prototype, Animal.prototype, Ben.prototype);
var foo = new Ben();
foo.talk();
function Employee(name){
this.name = name;
this.dept = 'IT';
}
Employee.prototype.details = function(name,dept){
this.name = name;
this.dept = dept;
console.log('Employee Name : '+this.name +' And His Dept : '+ this.dept);
}
function Developer(){
Employee.call(this, 'JsNinja');
}
Developer.prototype = Object.create(Employee.prototype);
Developer.prototype.constructor = Developer;
var dev1 = new Developer();
console.log(dev1.details('srinivas', 'Devopps'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment