Having the parent class:
function Animal() {
// do something
}
Animal.prototype.walk = function() {
alert('I am walking.');
};
and the child class:
function Lion() {
// do something
}
if I want the Lion
to inherit Animal
's prototype a common practice is this:
Lion.prototype = new Animal();
// Set the constructor to Lion, because now it points to Animal
Lion.prototype.constructor = Lion;
Is this in any way different from this (as result not as performance)?
$.extend(Lion.prototype, Animal.prototype);
For non jquery developers: $.extend
copies all the prototype methods and attributes, one by one from Animal to Lion.
I am not a big expert of inheritance in javascript. I usually use an MVC framework for front-end development where everything just works, but now I would love to understand also how inheriting the prototype works.
NOTE! I read many articles about the subject, I know there are many "plugins" that implements the Class functionality. This is not what I need. Please answer the question, not just link articles about the subject (except if that answers it).
Thank you!