WatsonFalcon
WatsonFalcon

Reputation: 21

Not getting the proper Log in Javascript

I was just testing stuff because I started using VSCode , then I realised something that I think is wrong. whenever I just log something that is calculated using a method, It logs function:method name. Any suggestions ?

example :

class square {
    constructor(width, height) {
        this.width = width;
        this.height = height;
    }

    get area() {
        return this.calculateArea
    }

    calculateArea() {
        this.width * this.height
    }
}

const square1 = new square(5, 8);
console.error(square1.area);

this logs [Function: calculateArea].

Upvotes: 3

Views: 32

Answers (1)

Brain Foo Long
Brain Foo Long

Reputation: 2087

You return the function, not the result.

Should be return this.calculateArea()

Upvotes: 3

Related Questions