File tree Expand file tree Collapse file tree 5 files changed +24
-173
lines changed
Expand file tree Collapse file tree 5 files changed +24
-173
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- //접근 제한자(Access modifier) - public, private, protected / es6에서는 접근 제한자를 지원하지 않았다 하지만 ts에서는 제공해준다.
2-
3- abstract class Car {
4- color : string ;
5- constructor ( color : string ) {
6- this . color = color ;
7- }
8- start ( ) : void {
9- console . log ( "start" ) ;
10- }
11- abstract doSomething ( ) : string ; //아무 작업을 하지 않은 추상 함수 상속받은 클래스에 해당 함수가 없다면 error 발생
12- }
13-
14- // const Car = new Car("red"); //-> error : 추상클래스는 new 인스턴스로 생성할 수 없다. 추상클래스는 청사진과 같다고 생각하며 된다. 따라서 오로지 상속을 통해서만 가능하다.
15-
16- class Bmw extends Car {
17- constructor ( color : string ) {
18- super ( color ) ;
19- // 참고로 'super()'는 부모(일반적인 super가 아님)의 constructor에 접근
20- }
21- // abstract doSomething()가 없다면 class는 error, 즉, 추상 클래스는 상속을 받은 쪽에서 해당 함수를 사용해야 한다.
22- doSomething ( ) : string {
23- // alert("do!"); //-> error : alert는 browser에서만 사용이 가능
24- console . log ( "do!" ) ;
25- return 'Do!' ;
26- }
27- // - private: 부모 name이 private인 경우 error가 나온다. 추가적으로 '#name'은 private로 인식한다.
28- // - protected: 부모 name이 protected인 경우 정상 동작한다. 그렇다면 public과 차이는 무엇인가.
29- /*
30- * new를 통해서 인스턴스 했을 경우 접근을 제한하게 된다. 즉, 자식 클래스에서는 부모 속성에 접근을 할 수 있으나 new 인스턴스인 경우 접근이 불가하다.
31- */
32- // - readonly: new 인스턴스를 통해서 값을 변경할 수 없다. 그렇다면 어떻게 해야 변경을 할 수 있을까?
33- /*
34- * 부모 constructor 내부에서 작업을 해야한다.
35- */
36- // - static: static은 정적 맴버 변수(property)를 만들어 줄 수 있다. static에 접근을 하기 위해서는 this가 아닌 class 이름으로 접근을 해야 한다.
37- // - abstract: abstract은 추상 클래스(class) 또는 함수, 변수를 만들어 준다.
38- }
39-
40- const z4 = new Bmw ( "black" ) ;
41- console . log ( z4 . doSomething ( ) ) ; //undefined가 출력되는 이유 : doSomething의 반환 값이 void이기 때문이다.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- {
2- "compilerOptions" : {
3- "target" : " es5" ,
4- "lib" : [
5- " dom" ,
6- " dom.iterable" ,
7- " esnext"
8- ],
9- "allowJs" : true ,
10- "skipLibCheck" : true ,
11- "allowSyntheticDefaultImports" : true ,
12- "strict" : true ,
13- "forceConsistentCasingInFileNames" : true ,
14- "noFallthroughCasesInSwitch" : true ,
15- "module" : " commonjs" ,
16- "outDir" : " dist" ,
17- "rootDir" : " src" ,
18- },
19- "include" : [
20- " src/**/*"
21- ],
22- "exclude" : [
23- " node_modules"
24- ]
1+ {
2+ "compilerOptions" : {
3+ "target" : " es5" ,
4+ "lib" : [
5+ " dom" ,
6+ " dom.iterable" ,
7+ " esnext"
8+ ],
9+ "allowJs" : true ,
10+ "skipLibCheck" : true ,
11+ "allowSyntheticDefaultImports" : true ,
12+ "strict" : true ,
13+ "forceConsistentCasingInFileNames" : true ,
14+ "noFallthroughCasesInSwitch" : true ,
15+ "module" : " commonjs" ,
16+ "outDir" : " dist" ,
17+ "rootDir" : " src" ,
18+ },
19+ "include" : [
20+ " src/**/*"
21+ ],
22+ "exclude" : [
23+ " node_modules"
24+ ]
2525}
You can’t perform that action at this time.
0 commit comments