Answer the question
In order to leave comments, you need to log in
Javascript can't understand inheritance logic?
Here is one code
function inherit(proto) {
function F() {}
F.prototype = proto;
var object = new F;
return object;
}
function extend(Child, Parent) {
var F = function() { }
F.prototype = Parent.prototype
Child.prototype = new F()
Child.prototype.constructor = Child
Child.superclass = Parent.prototype
}
F.prototype = proto;
F.prototype = Parent.prototype
F.prototype = Parent.prototype
Answer the question
In order to leave comments, you need to log in
prototype is not a parent. This is the class of the object.
In the second case, we make an empty constructor, then we say that this constructor makes objects of the Parent class.
After that, we create an object in which everything from the parent class is inherited in the prototype.
After that, we change the reference to the prototype constructor to match the object.
The 1st option takes the parent's prototype in the parameter and returns the inherited prototype, what you will do with it is entirely up to you.
The 2nd option takes 2 constructors and does relatively correct inheritance
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question