11//// { order: 3 }
22
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을 사용하여 동일한 클래스를 만드는 방법을 다룰 겁니다 .
66
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+ // 여러 가지 물건을 담을 수 있는 하나의 서랍이 있습니다 :
1010
1111class Drawer < ClothingType > {
1212 contents : ClothingType [ ] = [ ] ;
@@ -20,8 +20,8 @@ class Drawer<ClothingType> {
2020 }
2121}
2222
23- // In order to use a Drawer, you will need another
24- // type to work with :
23+ // Drawer를 사용하기 위해서
24+ // 또 다른 타입이 필요합니다 :
2525
2626interface Sock {
2727 color : string ;
@@ -31,31 +31,31 @@ interface TShirt {
3131 size : "s" | "m" | "l" ;
3232}
3333
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를 만들 수 있습니다 :
3636const sockDrawer = new Drawer < Sock > ( ) ;
3737
38- // Now we can add or remove socks to the drawer :
38+ // 이제 양말을 서랍에 추가하거나 삭제할 수 있습니다 :
3939sockDrawer . add ( { color : "white" } ) ;
4040const mySock = sockDrawer . remove ( ) ;
4141
42- // As well as creating a drawer for TShirts :
42+ // 티셔츠를 위한 서랍도 만들 수 있습니다 :
4343const tshirtDrawer = new Drawer < TShirt > ( ) ;
4444tshirtDrawer . add ( { size : "m" } ) ;
4545
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+ // 유니언을 사용하여 양말과 티셔츠가 섞인 서랍을 만들 수도 있습니다
4848
4949const mixedDrawer = new Drawer < Sock | TShirt > ( ) ;
5050
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+ // 클래스에 프로퍼티를 제공할 것입니다 :
5555
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 코드를 제거해야 합니다
5959
6060/**
6161 * @template {{}} ClothingType
@@ -77,16 +77,16 @@ class Dresser {
7777 }
7878}
7979
80- // Then we create a new type via JSDoc :
80+ // 그러고 나서 JSDoc을 통해 새로운 타입을 만듭니다 :
8181
8282/**
83- * @typedef {Object } Coat An item of clothing
84- * @property {string } color The colour for coat
83+ * @typedef {Object } Coat 의류 아이템
84+ * @property {string } color 코트 색상
8585 */
8686
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을 사용합니다 .
9090
9191/** @type {Dresser<Coat> } */
9292const coatDresser = new Dresser ( ) ;
0 commit comments