File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,3 +160,48 @@ interface IService {
160160---
161161
162162## Classes
163+
164+ - ** Modifiers** <br >
165+
166+ ``` ts
167+ class Example {
168+ constructor (a : number , b : number ) {
169+ this .a = a ;
170+ this .b = b ;
171+ }
172+
173+ /* prevents assignments to the field outside
174+ of the constructor */
175+ readonly a: number ;
176+
177+ /* visible only inside classes inherited from
178+ the current class (not from outside) */
179+ protected b: number ;
180+
181+ /* visible only inside current class
182+ (not from inherited and outside) */
183+ private secret = " hello" ;
184+
185+ /* allows access without creating an instance
186+ of the class may be supplemented by modifiers */
187+ static sayHello() {
188+ console .log (" Hello!" );
189+ }
190+ }
191+ ```
192+
193+ ``` ts
194+ // Extending a class
195+ class NewExmaple extends Example {
196+ constructor (a : number , b : number , c : number ) {
197+ super (a , b );
198+ this .c = c ;
199+ }
200+
201+ c: number ;
202+
203+ sayHello(name : string ) {
204+ console .log (` Hello ${name } ` );
205+ }
206+ }
207+ ```
You can’t perform that action at this time.
0 commit comments