JavaScript - Object Constructor with properties and functions

 function Rectangle(height, width) {  
  this.height = height;  
  this.width = width;  
  this.calcArea = function() {  
    return this.height * this.width;  
  };   
  this.calcPerimeter = function() {  
   return 2*(this.height+this.width);    
  }  
 }  
 var rex = new Rectangle(7,3);  
 var area = rex.calcArea();  
 var perimeter = rex.calcPerimeter();  

No comments:

Post a Comment