Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

chaining prototype methods

function Shape(){//from  ww  w.j a  v a  2  s .  co  m
   this.isDrawable = true;
}
Shape.prototype.getDrawable = function(){
   return this.isDrawable;
};

function Rectangle(){
   this.hasFourEdges = false;
}

//inherit from Shape
Rectangle.prototype = new Shape();

Rectangle.prototype.getFourEdges = function (){
   return this.hasFourEdges;
};

var instance = new Rectangle();
console.log(instance.getDrawable());   //true
Source by www.java2s.com #
 
PREVIOUS NEXT
Tagged: #chaining #prototype #methods
ADD COMMENT
Topic
Name
9+1 =