Skip to content

Commit febe6b8

Browse files
Merge pull request #30 from yahma25/Translation-to-ko-playground-Classes-101
Translate 1 file to ko - Classes 101
2 parents aeffd3d + 7dc6a92 commit febe6b8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// { order: 0 }
2+
3+
// 클래스는 생성자를 이용해서 생성되는
4+
// JavaScript 오브젝트의 특별한 타입입니다.
5+
// 클래스는 오브젝트와 아주 흡사하게 동작하며
6+
// Java/C#/Swift 같은 언어와 비슷한 상속 구조를 가집니다.
7+
8+
// 클래스 예시:
9+
10+
class Vendor {
11+
name: string;
12+
13+
constructor(name: string) {
14+
this.name = name;
15+
}
16+
17+
greet() {
18+
return "Hello, welcome to " + this.name;
19+
}
20+
}
21+
22+
// 인스턴스는 new 키워드를 이용해서 생성할 수 있으며
23+
// 메서드를 호출하고
24+
// 오브젝트의 프로퍼티에 접근할 수 있습니다.
25+
26+
const shop = new Vendor("Ye Olde Shop");
27+
console.log(shop.greet());
28+
29+
// 오브젝트를 하위 클래스로 만들 수 있습니다.
30+
// 이름뿐만 아니라 다양한 음식을 가진 카트:
31+
32+
class FoodTruck extends Vendor {
33+
cuisine: string;
34+
35+
constructor(name: string, cuisine: string) {
36+
super(name);
37+
this.cuisine = cuisine;
38+
}
39+
40+
greet() {
41+
return "Hi, welcome to food truck " + this.name + ". We serve " + this.cuisine + " food.";
42+
}
43+
}
44+
45+
// 새로운 FoodTruck을 생성하기 위하여
46+
// 매개변수가 2개 필요하다고 작성했기 때문에
47+
// TypeScript는 매개변수를 하나만 사용할 경우, 에러를 표시합니다:
48+
49+
const nameOnlyTruck = new FoodTruck("Salome's Adobo");
50+
51+
// 매개변수 2개를 정확하게 전달하면
52+
// FoodTruck의 새로운 인스턴스를 생성할 수 있습니다:
53+
54+
const truck = new FoodTruck("Dave's Doritos", "junk");
55+
console.log(truck.greet());

0 commit comments

Comments
 (0)