When I run the following script, I get the error that sub.hello
is not a function. Why not? Sub
's prototype is Base
and Base
has the function hello
. Since Sub
does not have the function hello
, shouldn't its prototype then be checked for the function?
function Base() {
}
Base.prototype.hello = function() {
alert("hello");
}
Sub.prototype = Base;
function Sub() {
Base.call(this);
}
var sub = new Sub();
sub.hello();