Guest User

Untitled

a guest
Aug 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. Access a base classes variable from within a child class
  2. function BaseClass()
  3. {
  4. var privateMap = {"type": "BaseClass"};
  5. }
  6.  
  7. function ChildClass()
  8. {
  9. // How can I access BaseClass's private variable privateMap?
  10. privateMap["type"] = "ChildClass";
  11. }
  12.  
  13. ChildClass.prototype = new BaseClass();
  14. ChildClass.prototype.constructor = ChildClass;
  15.  
  16. var Base = function()
  17. {
  18. var privateMap = {"type":"Base"};
  19.  
  20. this.changeMap = function(arg) {
  21. privateMap['type'] = arg;
  22. console.log('Changed Map to ' + privateMap['type'])
  23. }
  24.  
  25. }
  26. var Child = new Base;
  27.  
  28. Child.changeMap('Child1')
  29.  
  30. console.log(Child.privateMap)//undefined
Add Comment
Please, Sign In to add comment