Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Access a base classes variable from within a child class
- function BaseClass()
- {
- var privateMap = {"type": "BaseClass"};
- }
- function ChildClass()
- {
- // How can I access BaseClass's private variable privateMap?
- privateMap["type"] = "ChildClass";
- }
- ChildClass.prototype = new BaseClass();
- ChildClass.prototype.constructor = ChildClass;
- var Base = function()
- {
- var privateMap = {"type":"Base"};
- this.changeMap = function(arg) {
- privateMap['type'] = arg;
- console.log('Changed Map to ' + privateMap['type'])
- }
- }
- var Child = new Base;
- Child.changeMap('Child1')
- console.log(Child.privateMap)//undefined
Add Comment
Please, Sign In to add comment