javascript inherance? with Private vars and methods too -
hy need inherent class another.
parent has private var "_data" , private method "_test" , public method "add" child have public method "add", uses private method parent "_test" , private var "_data".
how do this?
var parent = function(){ var _data = {}; var _test = function(){alert('test')}; this.add = function(){alert('add parent')} } var child = function(){ this.add = function(){// here uses _data , _test parent class alert('add child') } } // inherent child parent // instance child , use add method
and think im miss prototype concept (javascript inheritance)
a simple inheritance:
function createchild(){ child.prototype=new parent() return new child() }
this way fresh initialization of parent every child.
Comments
Post a Comment