-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-classic-pattern.js
61 lines (38 loc) · 1.45 KB
/
class-classic-pattern.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
class CLASSNAME {
#private_field; // <- if private, the field isn't an implicit variable, so you need to write it here
constructor() {
// log "this" return the "class object"
// costructor lounch all inner element
this.my_open_field = {}
this.#private_field = {}
this.#autostart_private_method()
this.autostart_open_method()
}
#autostart_private_method() {
// this method is accessible into the class but not from outside
this.my_open_field = "hello world!"
this.#private_field = "hello to me!"
}
autostart_open_method() {
// this method is accessible and can be launched
// from any position (inside and ouside class)
// and can set (see set_private_field) and
// return open and private (see get_method_exemple) data
// ...obvius, for do that, you need a return or callback system
this.my_open_field = "hello beautyful world!"
this.#private_field = "hello to you, dev!"
}
set_private_field(str) {
// yes, it's horrible but you can override
// a private field via open method
this.#private_field = str
}
get_method_exemple() {
// yes, you can return a private field via open method
return [
this.my_open_field, // return the open data, ok
this.#private_field // return the private data, ops! wow!
]
}
}
const classistance = new CLASSNAME()