-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path3-class.js
More file actions
29 lines (23 loc) · 652 Bytes
/
Copy path3-class.js
File metadata and controls
29 lines (23 loc) · 652 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
'use strict';
const containerValue = Symbol('containerValue');
class Container {
constructor(value) {
Object.defineProperty(this, containerValue, {
configurable: false,
enumerable: false,
writable: false,
value,
});
}
getValue() {
return this[containerValue];
}
}
// Usage
const container1 = new Container(150);
console.dir({ container1 });
console.log('container1.getValue() =', container1.getValue());
const person = { name: 'Marcus', born: 121, city: 'Roma' };
const container2 = new Container({ person });
console.dir({ container2 });
console.log('container2.getValue() =', container2.getValue());