Advertisement
shanimal

Prototype Inheritance / Extending a jQuery wrapped element

Mar 27th, 2012
54
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(){console.log("Fluid.fluidCallWater",this.waterFn(),this);}
  15. }
  16. var Water = function(target){
  17.     this.__proto__ = new Fluid(target)
  18.     this.draw = function(){console.log("Water.draw",this);}
  19.     this.waterFn = function(){console.log("Water.waterFn",this);}
  20.     this.fluidOR = function(){console.log("Water.fluidOR",this);}
  21. }
  22.  
  23. var w = new Water($("<div />"));
  24. w.draw();
  25. w.baseFn();
  26. w.fluidFn();
  27. w.waterFn();
  28. w.baseOR();
  29. w.fluidOR();
  30. w.fluidCallWater();
  31. w.baseCallWater();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement