Circle class - Node.js Object

Node.js examples for Object:Class Definition

Description

Circle class

Demo Code


var Circle = function(radius) {
  this.radius = radius;// w w  w  .  j  a  v  a2s.c om
};

Circle.prototype.area = function() {
  return Math.PI*Math.pow(this.radius, 2);
};

var a = new Circle(3),
    b = new Circle(4);

console.log(a.area().toFixed(2)); // 28.27
console.log(b.area().toFixed(2)); // 50.27

Related Tutorials