33. Methods - Help with calling the function


Finished the exercise, and for kicks, I'm now trying to actually call the function and calculate the circle area and perimeter.


function Circle (radius) {
    this.radius = radius;
    this.area = function () {
        return Math.PI * this.radius * this.radius;
    // define a perimeter method here
    this.perimeter = function() {
        return 2 * Math.PI * this.radius;

var newCircle = new Circle(5);
console.log(this.perimeter, this.area);

I used newCircle to construct an object, and gave it a radius of 5, but I can't actually log the area and radius to the console.

Both return as "undefined".

Help please?


Instead of this.perimeter use newCircle.perimeter, same goes for area.


Nope, doesn't work. That just returns the function:

function () {
      return Math.PI * this.radius * this.radius;
function () {
      return 2 * Math.PI * this.radius;

This is what I'm getting in the console...


That is the default output when you console print a variable. The right way to make the call is


Btw, this is what is used extensively in AngularJS within controllers and services.


That did it, thanks. Makes total sense as well as they are both functions, and need to be called.