The es6 class,getter method cannot be called

The

code is as follows. While learning the class usage of es6, an error occurred when calling the getter method

console.log(c.radius());//getter
              ^

TypeError: c.radius is not a function

how do I use that? How does everyone use it?

class Circle {
    constructor(radius) {
        this._radius = radius;
        Circle.circlesMadePP;
    };
    static draw(circle, canvas) {
        // Canvas
    };
    static get circlesMade() {
        return !this._count ? 0 : this._count;
    };
    static set circlesMade(val) {
        this._count = val;
    };
    area() {
        return Math.pow(this.radius, 2) * Math.PI;
    };
    get radius() {
        return this._radius;
    };
    set radius(radius) {
        if (!Number.isInteger(radius))
            throw new Error("");
        this._radius = radius;
    };
}

let c=new Circle(5);//
Circle.draw(c,6);//

console.log(c.radius());//getter
console.log(c.area());//
Feb.28,2021

just c.radius directly, without ()


here is obviously the subject you don't understand 'getter/setter''. The purpose of this thing is to hide the true identity of the variable and replace it with itself, so you don't need to use () to execute the call, just access it.


just c.radius directly, which is a getter attribute

Menu