File tree Expand file tree Collapse file tree 2 files changed +3
-31
lines changed Expand file tree Collapse file tree 2 files changed +3
-31
lines changed Original file line number Diff line number Diff line change 1
- "use strict" ;
2
- var Department = /** @class */ ( function ( ) {
3
- function Department ( id , name ) {
4
- this . id = id ;
5
- this . name = name ;
6
- // private id: string;
7
- // private name: string;
8
- this . employees = [ ] ;
9
- // this.id = id;
10
- // this.name = n
11
- }
12
- Department . prototype . describe = function ( ) {
13
- console . log ( "Department (" . concat ( this . id , "): " ) . concat ( this . name ) ) ;
14
- } ;
15
- Department . prototype . addEmployee = function ( employee ) {
16
- this . employees . push ( employee ) ;
17
- } ;
18
- Department . prototype . printEmployeeInformation = function ( ) {
19
- console . log ( this . employees . length ) ;
20
- console . log ( this . employees ) ;
21
- } ;
22
- return Department ;
23
- } ( ) ) ;
24
- var accounting = new Department ( '1' , 'Accounting' ) ;
25
- accounting . addEmployee ( 'Max' ) ;
26
- accounting . addEmployee ( 'Manu' ) ;
27
- // accounting.employees[2] = 'Anna';
28
- accounting . describe ( ) ;
29
- accounting . printEmployeeInformation ( ) ;
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ class Department {
2
2
// private id: string;
3
3
// private name: string;
4
4
private employees : string [ ] = [ ] ;
5
-
6
- constructor ( private id : string , public name : string ) {
5
+ // readonly๋ ํ๋กํผํฐ๋ฅผ ์ด๊ธฐํํ ํ ์์ ํ ์ ์๋ค. ์ฆ, ํ๋ฒ ํ ๋น ๋๋ฉด ๋ณ๊ฒฝ๋๋ฉด ์๋๋ ๊ณ ์ ๋ฒํธ๋ค์ ์ค์ ํ ๋ readonly๋ฅผ ์ฌ์ฉํ๋ค.
6
+ constructor ( private readonly id : string , public name : string ) {
7
7
// this.id = id;
8
8
// this.name = n
9
9
}
@@ -12,6 +12,7 @@ class Department {
12
12
}
13
13
14
14
addEmployee ( employee : string ) {
15
+ // this.id = '2'; // readonly์ด๊ธฐ ๋๋ฌธ์ error๊ฐ ๋ฐ์ํ๋ค.
15
16
this . employees . push ( employee ) ;
16
17
}
17
18
printEmployeeInformation ( ) {
You canโt perform that action at this time.
0 commit comments