In C#, we have concept about abstract method, and how to apply this in Javascript. Example, I have an example:
function BaseClass() {
this.hello = function() {
this.talk();
}
this.talk = function() {
alert("I'm BaseClass");
}
};
function MyClass() {
this.talk = function() {
alert("I'm MyClass");
}
BaseClass.call(this);
};
MyClass.prototype = new BaseClass();
var a = new MyClass();
a.hello();
How the function hello() in BaseClass call the function do() from MyClass when the object is an instance of MyClass. The alert result must be "I'm MyClass". Please help me. Thanks.
virtual
/override
, notabstract
. – AltdorferBaseClass.call(this);
line and it works, sincethis.talk=...
overrides the base method. Or you can startMyClass
withBaseClass.call(...)
(at the begining, not the end). But if you are usingcall
then there is no need for defining prototype. – Rotl