1
1
//// { order: 3 }
2
2
3
- // This example is mostly in TypeScript, because it is much
4
- // easier to understand this way first. At the end we'll
5
- // cover how to create the same class but using JSDoc instead .
3
+ // ๋จผ์ ์ด ๋ฐฉ์์ผ๋ก ์ดํดํ๋ ๊ฒ ํจ์ฌ ์ฌ์ฐ๋ฏ๋ก
4
+ // ์์๋ ๋๋ถ๋ถ TypeScript๋ก ์์ฑํ์ต๋๋ค.
5
+ // ๋ง์ง๋ง์๋ JSDoc์ ์ฌ์ฉํ์ฌ ๋์ผํ ํด๋์ค๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ค๋ฃฐ ๊ฒ๋๋ค .
6
6
7
- // Generic Classes are a way to say that a particular type
8
- // depends on another type. For example, here is a drawer
9
- // which can hold any sort of object, but only one type :
7
+ // ์ ๋ค๋ฆญ ํด๋์ค๋ ํน์ ํ์
์ด ๋ค๋ฅธ ํ์
์ ๋ฐ๋ผ ๋์ํ๋ค๋ ๊ฒ์ ๋ณด์ฌ์ฃผ๋ ํ๋์ ๋ฐฉ์์
๋๋ค.
8
+ // ์๋ฅผ ๋ค์ด, ์ฌ๊ธฐ์๋ ํ ์ข
๋ฅ๋ง ์์ง๋ง
9
+ // ์ฌ๋ฌ ๊ฐ์ง ๋ฌผ๊ฑด์ ๋ด์ ์ ์๋ ํ๋์ ์๋์ด ์์ต๋๋ค :
10
10
11
11
class Drawer < ClothingType > {
12
12
contents : ClothingType [ ] = [ ] ;
@@ -20,8 +20,8 @@ class Drawer<ClothingType> {
20
20
}
21
21
}
22
22
23
- // In order to use a Drawer, you will need another
24
- // type to work with :
23
+ // Drawer๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์
24
+ // ๋ ๋ค๋ฅธ ํ์
์ด ํ์ํฉ๋๋ค :
25
25
26
26
interface Sock {
27
27
color : string ;
@@ -31,31 +31,31 @@ interface TShirt {
31
31
size : "s" | "m" | "l" ;
32
32
}
33
33
34
- // We can create a Drawer just for socks by passing in the
35
- // type Sock when we create a new Drawer :
34
+ // ์๋ก์ด Drawer๋ฅผ ๋ง๋ค ๋ Sock ํ์
์ ์ ๋ฌํ์ฌ
35
+ // ์๋ง ์ ์ฉ์ ์๋ก์ด Drawer๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค :
36
36
const sockDrawer = new Drawer < Sock > ( ) ;
37
37
38
- // Now we can add or remove socks to the drawer :
38
+ // ์ด์ ์๋ง์ ์๋์ ์ถ๊ฐํ๊ฑฐ๋ ์ญ์ ํ ์ ์์ต๋๋ค :
39
39
sockDrawer . add ( { color : "white" } ) ;
40
40
const mySock = sockDrawer . remove ( ) ;
41
41
42
- // As well as creating a drawer for TShirts :
42
+ // ํฐ์
์ธ ๋ฅผ ์ํ ์๋๋ ๋ง๋ค ์ ์์ต๋๋ค :
43
43
const tshirtDrawer = new Drawer < TShirt > ( ) ;
44
44
tshirtDrawer . add ( { size : "m" } ) ;
45
45
46
- // If you're a bit eccentric, you could even create a drawer
47
- // which mixes Socks and TShirts by using a union:
46
+ // ์ฌ๋ฌ๋ถ์ด ์กฐ๊ธ ๋ณ๋์ ํธ์ด๋ผ๋ฉด,
47
+ // ์ ๋์ธ์ ์ฌ์ฉํ์ฌ ์๋ง๊ณผ ํฐ์
์ธ ๊ฐ ์์ธ ์๋์ ๋ง๋ค ์๋ ์์ต๋๋ค
48
48
49
49
const mixedDrawer = new Drawer < Sock | TShirt > ( ) ;
50
50
51
- // Creating a class like Drawer without the extra TypeScript
52
- // syntax requires using the template tag in JSDoc. In this
53
- // example we define the template variable, then provide
54
- // the properties on the class :
51
+ // ์ถ๊ฐ TypeScript ๊ตฌ๋ฌธ ์์ด Drawer์ ๊ฐ์ ํด๋์ค๋ฅผ ๋ง๋๋ ๊ฒ์
52
+ // JSDoc์์ ํ
ํ๋ฆฟ ํ๊ทธ ์ฌ์ฉ์ ์๊ตฌํฉ๋๋ค.
53
+ // ์ด ์์์์ ํ
ํ๋ฆฟ ๋ณ์๋ฅผ ์ ์ํ๊ณ ,
54
+ // ํด๋์ค์ ํ๋กํผํฐ๋ฅผ ์ ๊ณตํ ๊ฒ์
๋๋ค :
55
55
56
- // To have this work in the playground, you'll need to change
57
- // the settings to be a JavaScript file, and delete the
58
- // TypeScript code above
56
+ // playground์์ ์์
ํ๊ธฐ ์ํด์,
57
+ // ์ฌ๋ฌ๋ถ์ JavaScript ํ์ผ์ด ๋๋๋ก ์ค์ ์ ๋ณ๊ฒฝํ๊ณ
58
+ // ์์ ์๋ TypeScript ์ฝ๋๋ฅผ ์ ๊ฑฐํด์ผ ํฉ๋๋ค
59
59
60
60
/**
61
61
* @template {{}} ClothingType
@@ -77,16 +77,16 @@ class Dresser {
77
77
}
78
78
}
79
79
80
- // Then we create a new type via JSDoc :
80
+ // ๊ทธ๋ฌ๊ณ ๋์ JSDoc์ ํตํด ์๋ก์ด ํ์
์ ๋ง๋ญ๋๋ค :
81
81
82
82
/**
83
- * @typedef {Object } Coat An item of clothing
84
- * @property {string } color The colour for coat
83
+ * @typedef {Object } Coat ์๋ฅ ์์ดํ
84
+ * @property {string } color ์ฝํธ ์์
85
85
*/
86
86
87
- // Then when we create a new instance of that class
88
- // we use @type to assign the variable as a Dresser
89
- // which handles Coats .
87
+ // Dresser ํด๋์ค์ ์๋ก์ด ์ธ์คํด์ค๋ฅผ ์์ฑํ ๋
88
+ // ์ฝํธ๋ฅผ ๋ค๋ฃจ๋ Dresser๋ก
89
+ // ๋ณ์๋ฅผ ํ ๋นํ๊ธฐ ์ํด @type์ ์ฌ์ฉํฉ๋๋ค .
90
90
91
91
/** @type {Dresser<Coat> } */
92
92
const coatDresser = new Dresser ( ) ;
0 commit comments