javascript inherance? with Private vars and methods too

Posted by Totty on Stack Overflow See other posts from Stack Overflow or by Totty
Published on 2010-04-29T23:23:26Z Indexed on 2010/04/29 23:27 UTC
Read the original article Hit count: 254

Filed under:

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 (http://stackoverflow.com/questions/892467/javascript-inheritance)

© Stack Overflow or respective owner

Related posts about JavaScript