|
33 | 33 | |27|[Check if a node is in the viewport](#Check-if-a-node-is-in-the-viewport)|
|
34 | 34 | |28|[Notify when element size is changed](#Notify-when-element-size-is-changed)|
|
35 | 35 | |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)| |
36 | 37 |
|
37 | 38 |
|
38 | 39 |
|
@@ -614,3 +615,33 @@ document.addEventListener("visibilitychange", onVisibilitychange)
|
614 | 615 | ```
|
615 | 616 |
|
616 | 617 |
|
| 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 | + |