Advertisement
shanimal

Javascript Inheritance / jQuery DOM Element

Mar 27th, 2012
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Base = function(target){
  2.     this.__proto__ = target;
  3.     this.draw = function(){console.log("Base.draw",this);}
  4.     this.baseFn = function(){console.log("Base.baseFn",this);}
  5.     this.baseOR = function(){console.log("Base.baseOR",this);}
  6.     this.baseCallWater = function(){console.log("Base.baseCallWater",this.waterFn(),this);}
  7. }
  8. var Fluid = function(target){
  9.     this.__proto__ = new Base(target)
  10.     this.draw = function(){console.log("Fluid.draw",this);}
  11.     this.fluidFn = function(){console.log("Fluid.fluidFn",this);}
  12.     this.fluidOR = function(){console.log("Fluid.fluidOR",this);}
  13.     this.baseOR = function(){console.log("Fluid.baseOR",this);}
  14.     this.fluidCallWater = function(){
  15.         console.log("Fluid.fluidCallWater",this.waterFn(),this);
  16.     }
  17. }
  18. var Water = function(target){
  19.     this.__proto__ = new Fluid(target)
  20.     this.draw = function(){console.log("Water.draw",this);}
  21.     this.waterFn = function(){var r = "Water.waterFn";console.log(r,this);return r;}
  22.     this.fluidOR = function(){console.log("Water.fluidOR",this);}
  23. }
  24.  
  25. var w = new Water($("<div />"));
  26. w.draw(); // Water.draw [div]
  27. w.baseFn(); // Base.baseFn [div]
  28. w.fluidFn(); // Fluid.fluidFn [div]
  29. w.waterFn(); // Water.waterFn [div]
  30. w.baseOR(); // Fluid.baseOR [div]
  31. w.fluidOR(); // Water.fluidOR [div]
  32. w.fluidCallWater(); // Water.waterFn [div] Fluid.fluidCallWater Water.waterFn [div]
  33. w.baseCallWater(); // Water.waterFn [div] Base.baseCallWater Water.waterFn [div]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement