GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs: enum 타입 수정 · dev-language/TypeScript_prac@1b4e500

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • 1-types
    • 1-8-enum.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎1-types/1-8-enum.ts‎

Copy file name to clipboardExpand all lines: 1-types/1-8-enum.ts
+22-22Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
/**
33
* Enum
44
* 여러 상수 값을 한곳에 모아서 관리할 수 있는 타입
5-
* 타입이 보장되고 타입의 값이 변화되지 않으므로 안전하게 타입을 관리할 수 있다.
65
* enum에 값을 정하지 않으면 위에서부터 0부터 1씩 늘어난다.
76
* enum에 기본값(숫자, 문자)을 정할 수 있다.
7+
8+
* 타입스크립트에서 enum은 타입이 정확하게 보장되지 않기 때문에 사용하지 않는것이 좋다.
9+
* enum을 사용하지 않고 Union 타입을 사욯아는것이 좋다.
810
*/
911

1012
/* ======= JAVASCRIPT: 상수를 정의할때 대문자로 지정해주는것이 좋다. ======= */
@@ -40,27 +42,6 @@
4042
console.log("Cookie.RefreshName --->", Cookie.RefreshName); // RefreshToken
4143
console.log("MyCookie --->", MyCookie); // AccessToken
4244

43-
/* ======= 함수도 enum에 작성 가능하다. ======= */
44-
45-
enum Colors {
46-
Red = getColorCode("RED"),
47-
Green = getColorCode("GREEN"),
48-
Blue = getColorCode("BLUE"),
49-
}
50-
51-
function getColorCode(color: string): number {
52-
// 실제로는 color 값에 따라 적절한 컬러 코드를 계산하는 로직을 수행한다고 가정합니다.
53-
if (color === "RED") 0xff0000; // 빨간색의 컬러 코드
54-
else if (color === "GREEN") 0x00ff00; // 초록색의 컬러 코드
55-
else if (color === "BLUE") 0x0000ff; // 파란색의 컬러 코드
56-
57-
return 0x000000;
58-
}
59-
60-
console.log(Colors.Red); // 16711680
61-
console.log(Colors.Green); // 65280
62-
console.log(Colors.Blue); // 255
63-
6445
enum Month {
6546
Jan = 1,
6647
Feb,
@@ -105,4 +86,23 @@
10586
Nov: 11,
10687
Dec: 12
10788
} */
89+
90+
/* ======= 함수도 enum에 작성 가능하다. ======= */
91+
92+
enum Colors {
93+
Red = getColorCode("RED"),
94+
Green = getColorCode("GREEN"),
95+
Blue = getColorCode("BLUE"),
96+
}
97+
98+
function getColorCode(color: string): number {
99+
if (color === "RED") 0xff0000;
100+
else if (color === "GREEN") 0x00ff00;
101+
else if (color === "BLUE") 0x0000ff;
102+
return 0x000000;
103+
}
104+
105+
console.log(Colors.Red); // 16711680
106+
console.log(Colors.Green); // 65280
107+
console.log(Colors.Blue); // 255
108108
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.