| 1 |
class Cl { |
| 2 |
#privateField = "top secret string"; |
| 3 |
|
| 4 |
constructor() { |
| 5 |
this.publicField = "not secret string"; |
| 6 |
} |
| 7 |
|
| 8 |
get #privateFieldValue() { |
| 9 |
return this.#privateField; |
| 10 |
} |
| 11 |
|
| 12 |
set #privateFieldValue(newValue) { |
| 13 |
this.#privateField = newValue; |
| 14 |
} |
| 15 |
|
| 16 |
publicGetPrivateField() { |
| 17 |
return this.#privateFieldValue; |
| 18 |
} |
| 19 |
|
| 20 |
publicSetPrivateField(newValue) { |
| 21 |
this.#privateFieldValue = newValue; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
const cl = new Cl(); |
| 26 |
|
| 27 |
expect(cl.publicGetPrivateField()).toEqual("top secret string"); |
| 28 |
|
| 29 |
cl.publicSetPrivateField("new secret string"); |
| 30 |
expect(cl.publicGetPrivateField()).toEqual("new secret string"); |
| 31 |
|