Skip to content

Commit b0c1106

Browse files
authored
๐Ÿ”€: Merge pull request #9 from Programming-Contents-List/lecture/6
๐Ÿ”€: main๋ธŒ๋ Œ์น˜๋ฅผ ์ตœ์‹ ํ™” ํ•˜๊ธฐ์œ„ํ•œ merge
2 parents d231085 + 2c94919 commit b0c1106

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

โ€Žsrc/index.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
//intersection types
1+
//์ ‘๊ทผ ์ œํ•œ์ž(Access modifier) - public, private, protected / es6์—์„œ๋Š” ์ ‘๊ทผ ์ œํ•œ์ž๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์•˜๋‹ค ํ•˜์ง€๋งŒ ts์—์„œ๋Š” ์ œ๊ณตํ•ด์ค€๋‹ค.
22

3-
import { InterCar, InterToy } from "./utils/data.interface";
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+
}
413

5-
const toyCar: InterToy & InterCar = {
6-
name: 'ํƒ€์š”',
7-
start() { },
8-
color: 'blue',
9-
price: 1000,
10-
}
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์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

0 commit comments

Comments
ย (0)