So I'm currently working with JavaScript inheritance using multiple classes, so there are multiple levels to the inheritance.
I've looked around for a lot of methods and the easiest and best method I've found is using .call(). So for example:
function DerivedClass ( para1, para2)
{
BaseClass.call(this, para1, para2);
//Insert more code here
}
DerivedClass.prototype = Object.create(BaseClass.prototype);
DerivedClass.prototype.constructor = DerivedClass;
Now, this works for me and that's fine, I'm happy with that. But I'm the sort of programmer that needs to know why or how something works before I can continue.
However, the above code works fine, and exactly the same (at least for what I'm doing with it), if I only use .call() and don't put the .prototype and .constructor stuff at the end.
Could someone explain to me why the two bottom lines are necessary with this method if the inheritance still works fine without them?
Thanks.