I am implementing Prototypal inheritence in java script using simple assigning of prototype this is my code -
var Rectangle = function(heigth, width) {
this.height = height;
this.width = width;
}
Rectangle.prototype.area = function() {
return this.height*this.width;
}
var Square = function(length) {
this.height = this.width = length;
}
Square.prototype = Rectangle.prototype;
var sqr1 = new Square(5);
console.log(sqr1.area());
But at the place of Square.prototype = Rectangle.prototype it is recommended to use Square.prototype = Object.create(Rectangle.prototype). Can anyone tell me the underlying difference because the above code is working fine.