OneCompiler

encapsulation

141

class ClassWithPublicInstanceMethod {
publicMethod() {return "hello world public";}
static _protectedMethod() {return "hello world protected";}
static #privateMethod() {return "hello world private";}
get publicMethodGet() {return this.publicMethod();}
get protectedMethodGet() {return this.protectedMethod();}
static get privateMethodGet() {return this.#privateMethod();}
}

class ClassWith extends ClassWithPublicInstanceMethod {
publicMethod() {return "hello world";}
get sf() {return this.publicMethod();}
}

// const instance = new ClassWithPublicInstanceMethod();
console.log(ClassWith.privateMethodGet); // "hello world"
// console.log(instance.sf); // "hello world"