Need your help to understand what is the Difference between Prototype and Object.create Inheritance ?.
Please some one please describe
why console.log(objBird.a());
is giving error.
ref: https://jsfiddle.net/_private/4bmnctoz/
Code:
(function(){
console.clear();
var Living = function() {
var livingCell = 'I am living !';
this.isLiving = function() {
return livingCell;
}
};
Living.prototype.a = function() {
return 'here !!';
};
var objLiving = new Living();
console.log(objLiving.isLiving());
var Animal = function() {
var data = 'I am animal !';
this.express = function() {
return data;
};
};
Animal.prototype = new Living();
Animal.prototype.constructor = Animal;
var objAnimal = new Animal();
console.log(objAnimal.express());
console.log(objAnimal.a());
console.log(objAnimal.isLiving());
var Bird = function() {
var data = 'I am bird !';
this.express = function() {
return data;
};
};
var objBird = new Bird();
objBird.prototype = Object.create(Living);
objBird.prototype.constructor = Bird;
console.log(objBird.express());
console.dir(objBird);
console.log(objBird.a());
})();