Traditionally the object inheritance looks like the following:
function Parent() {
console.log('parent constructor');
}
Parent.prototype.method = function() {
console.log('parent method');
}
function Child() {
this.parent.apply(this,arguments);
console.log('child constructor');
}
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;
Child.prototype.parent = Parent;
but this is works too and looks better in my opinion:
function Parent() {
console.log('parent constructor');
}
Parent.prototype.method = function() {
console.log('parent method');
}
function Child() {
this.constructor.apply(this,arguments);
console.log('child constructor');
}
Child.prototype = Object.create(Parent.prototype);
// without next lines, constructor will be Parent
// Child.prototype.constructor = Child;
// Child.prototype.parent = Parent;
So,
What is the real reason to use first method ?
What problems I can get if I will use second method ?