JS class example

by programndial

HTML

<input type="button" id="testButton" value="Test" />

JavaScript

function Polygon(height, width) {
  this.height = height;
  this.width = width;

  Polygon.prototype.calcArea = function(string) {
    return this.height * this.width;
  }
}

testButton.onclick = function() {
  var newPoly = new Polygon(10, 25);
  alert(newPoly.calcArea());
}