I am new to Object Oriented Programming in Javascript. Yesterday I read about prototype
and prototype.constructor
in javascript and how they play their part in Javascript inheritance.
I have made a javascript function, inherited from one of the parent function. But I want some of the methods of this child not to be inherited by its child functions.
That is,
function A //parent
|
|`callA()
`makeA()
This is the main parent class.
function B //child of A
|
|` callB() //can be inherited
|` makeB() //cannot be inherited
|` callA() //inherited
` makeA() //inherited
B
is the child function I wish to write.
function C //child of B
|
|` callC();
|` makeC();
|` callB();
|` callA();
` makeA();
I am writing in this following manner:
function A(){}
A.prototype.callA = function()
{
alert('CallA');
}
A.prototype.makeA = function()
{
alert('makeA');
}
function B(){
function makeB(){ //This is not working I am not able to call makeB with B's object
alert('makeB');
}
}
B.prototype = new A();
B.prototype.constructor = B;
B.prototype.callB = function()
{
alert('callB');
}
function C(){}
C.prototype = new C();
C.prototype.constructor = C;
C.prototype.callC = function()
{
alert('callC');
}
C.prototype.makeC = function()
{
alert('makeC');
}
$(document).ready(function(){
var b = new B();
var c = new C();
$(document).click(function(){
c.callB();
c.callC();
b.callB();
b.makeB(); //not being called
});
});
How to do this part in JS inheritance. Private function for derived object.