-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.js
More file actions
48 lines (39 loc) · 748 Bytes
/
Copy pathdemo.js
File metadata and controls
48 lines (39 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Base } from './protected-base.js';
class B extends Base {
#_;
constructor () {
super();
this._get_();
this.#_.propB = 'B';
}
_sub_ (subs) {
super._sub_(subs);
subs.add((g) => this.#_ ||= g);
}
logGuarded () {
console.log(this.#_);
}
}
class C extends B {
#_;
constructor () {
super();
this._get_();
this.#_.propC = 'C';
}
_sub_ (subs) {
super._sub_(subs);
subs.add((p) => this.#_ ||= p);
}
}
const instance = new C();
instance.logGuarded();
// Attempt to subvert protected state
// (should not have any effect)
const subs = new Set(), newGuarded = { updated: true };
instance._sub_(subs);
for (const sub of subs) {
sub(newGuarded);
}
// Should report same original values
instance.logGuarded();