Posted By

elvman on 08/17/11


Tagged


Versions (?)

Polymorphism


 / Published in: JavaScript
 

  1. function A() {
  2. //private members
  3. var x;
  4.  
  5. //getter
  6. this.getX = function() {
  7. return x;
  8. }
  9.  
  10. //setter
  11. this.setX = function(newX) {
  12. x = newX;
  13. }
  14. }
  15.  
  16. A.prototype.DoIt = function(data) {
  17. console.log(data);
  18. }
  19.  
  20. B.prototype = new A();// Define sub-class
  21. B.prototype.constructor = B;
  22.  
  23. function B() {
  24. A.call(this);
  25. }
  26.  
  27. B.prototype.DoIt = function(data) {
  28. A.prototype.DoIt.call(this, data);
  29. console.log(data);
  30. }
  31.  
  32. var i = new B();

Report this snippet  

You need to login to post a comment.