xxxxxxxxxx
class Test {
public: string = 'hello';
#private: string = 'world';
print() {
return (this.public + this.#private);
}
}
const test = new Test()
console.log(test.print());
console.log(test.public + test.private)//error private is undefine
xxxxxxxxxx
class Animal { private name: string;
constructor(theName: string) { this.name = theName; }}
new Animal("Cat").name;Property 'name' is private and only accessible within class 'Animal'.2341Property 'name' is private and only accessible within class 'Animal'.Try