Reputation: 21
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
Reputation: 2087
You return the function, not the result.
Should be return this.calculateArea()
Upvotes: 3