Hy i need to inherent a class from another.
Parent has private var “_data” and private method “_test” and public method “add”
Now the child have a public method “add”, that uses the private method from the parent “_test” and the private var “_data”.
How do i do this?
var Parent = function(){
var _data = {};
var _test = function(){alert('test')};
this.add = function(){alert('add from parent')}
}
var Child = function(){
this.add = function(){// here uses the _data and _test from the Parent class
alert('add from child')
}
}
// something to inherent Child from Parent
// instance Child and use the add method
And i think im miss the prototype concept (Javascript inheritance)
A simple inheritance:
This way you get a fresh initialization of Parent for every Child.