Skip to content

Commit d593fc2

Browse files
authored
private class methods and fields
1 parent af8ebc2 commit d593fc2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
|27 | [Check if a node is in the viewport](#Check-if-a-node-is-in-the-viewport)|
3434
|28 | [Notify when element size is changed](#Notify-when-element-size-is-changed)|
3535
|29 | [Detect if Browser Tab is in the view](#Detect-if-Browser-Tab-is-in-the-view)|
36+
|30 | [Private class methods and fields](#Private-class-methods-and-fields)|
3637

3738

3839

@@ -614,3 +615,33 @@ document.addEventListener("visibilitychange", onVisibilitychange)
614615
```
615616
616617
618+
**[⬆ Back to Top](#table-of-contents)**
619+
### Private class methods and fields
620+
621+
class Students {
622+
#name;
623+
624+
constructor(){
625+
this.#name = "JS snippets";
626+
}
627+
628+
#privateMethod() {
629+
return 'Come and learn Js with us';
630+
}
631+
632+
getPrivateMessage() {
633+
return this.#privateMethod();
634+
}
635+
}
636+
637+
const instance = new Something();
638+
console.log(instance.name); //=> undefined
639+
console.log(instance.privateMethod); //=> undefined
640+
console.log(instance.getPrivateMessage()); //=> Come and learn Js with us
641+
642+
```
643+
644+
645+
646+
647+

0 commit comments

Comments
 (0)