Answer the question
In order to leave comments, you need to log in
OOP javascript why is this line needed?
Please explain why in this function
function extend(Child, Parent) {
var F = function() { }
F.prototype = Parent.prototype
Child.prototype = new F()
Child.prototype.constructor = Child
Child.superclass = Parent.prototype
}
Answer the question
In order to leave comments, you need to log in
Because in Parent there can be static methods which in child nafig didn't rest.
var Parent = (function() {
// конструктор
function Parent() {}
// статический метод
Parent.staticMethod = function() {
alert(1);
};
// обычный метод
Parent.prototype.publicMethod = function() {
alert(2);
};
return Parent;
}());
// в Child.prototype должен попасть только publicMethod
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question