You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/05-global-object/article.md
+4-19Lines changed: 4 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,7 @@
5
5
6
6
브라우저 환경에선 전역 객체를 `window`, Node.js 환경에선 `global`라고 부르는데, 각 호스트 환경마다 부르는 이름은 다릅니다.
7
7
8
-
<<<<<<< HEAD
9
-
전역 객체의 이름을 `globalThis`로 표준화하자는 내용이 최근에 자바스크립트 명세에 추가되었기 때문에 모든 호스트 환경이 이를 따라야 하죠. Chromium 기반이 아닌 몇몇 브라우저는 아직 `globalThis`를 지원하진 않지만, 이에 대한 폴리필(polyfill)을 쉽게 만들 수 있습니다.
10
-
=======
11
-
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. It's supported in all major browsers.
12
-
>>>>>>> upstream/master
8
+
전역 객체의 표준화된 이름으로 `globalThis`가 자바스크립트 명세에 추가되었습니다. 모든 주요 브라우저에서 지원합니다.
13
9
14
10
본 튜토리얼은 브라우저 환경에서 구동되기 때문에 `window`라는 전역 객체를 사용하도록 하겠습니다. 다른 호스트 환경에서 작업하고 계신다면 `window`대신 `globalThis`를 사용하시면 됩니다.
15
11
@@ -29,13 +25,9 @@ var gVar = 5;
29
25
alert(window.gVar); // 5 (var로 선언한 변수는 전역 객체 window의 프로퍼티가 됩니다)
30
26
```
31
27
32
-
<<<<<<< HEAD
33
-
하위 호환성 때문에 이런 방식으로 전역 객체를 사용해도 동작은 하지만, 이 방법은 쓰지 않으시길 바랍니다. [모듈](info:modules)을 사용하는 모던 자바스크립트는 이런 방식을 지원하지 않습니다.
34
-
=======
35
-
Function declarations have the same effect (statements with `function` keyword in the main code flow, not function expressions).
28
+
함수 선언문도 동일하게 동작합니다(함수 표현식이 아닌 메인 코드 흐름의 'function' 키워드를 사용한 문장에 한합니다).
36
29
37
-
Please don't rely on that! This behavior exists for compatibility reasons. Modern scripts use [JavaScript modules](info:modules) where such a thing doesn't happen.
38
-
>>>>>>> upstream/master
30
+
하위 호환성 때문에 이런 방식으로 전역 객체를 사용해도 동작은 하지만, 이 방법은 쓰지 않으시길 바랍니다. [모듈](info:modules)을 사용하는 모던 자바스크립트는 이런 방식을 지원하지 않습니다.
39
31
40
32
`var` 대신 `let`을 사용하면 위 예시와는 달리 전역 객체를 통해 변수에 접근할 수 없습니다.
41
33
@@ -91,14 +83,7 @@ if (!window.Promise) {
91
83
전역 객체엔 `Array`와 같은 내장 객체, `window.innerHeight`(뷰포트의 높이를 반환함)같은 브라우저 환경 전용 변수 등이 저장되어 있습니다.
92
84
- 전역 객체는 `globalThis`라는 보편적인 이름으로 불립니다.
93
85
94
-
<<<<<<< HEAD
95
-
하지만 '관습'에 따라 브라우저에서는 `window`, Node.js에서는 `global`이라는 이름으로 불릴 때가 많습니다. `globalThis`는 제안 목록에 추가 된 지 얼마 안 된 기능이기 때문에, 비 크로미움 기반 브라우저에선 지원하지 않습니다(폴리필을 구현하면 사용할 수 있습니다).
86
+
하지만 '관습'에 따라 브라우저에서는 `window`, Node.js에서는 `global`이라는 이름으로 불릴 때가 많습니다.
96
87
- 프로젝트 전체에서 꼭 필요한 변수만 전역 객체에 저장하도록 하고, 전역 변수는 가능한 한 최소한으로 사용합시다.
97
88
-[모듈](info:modules)을 사용하고 있지 않다면, 브라우저에서 `var`로 선언한 전역 변수는 전역 객체의 프로퍼티가 됩니다.
98
89
- 이해하기 쉽고 요구사항 변경에 쉽게 대응할 수 있는 코드를 구현하려면, `window.x`처럼 전역 객체의 프로퍼티에 직접 접근합시다.
99
-
=======
100
-
...But more often is referred by "old-school" environment-specific names, such as `window` (browser) and `global` (Node.js).
101
-
- We should store values in the global object only if they're truly global for our project. And keep their number at minimum.
102
-
- In-browser, unless we're using [modules](info:modules), global functions and variables declared with `var` become a property of the global object.
103
-
- To make our code future-proof and easier to understand, we should access properties of the global object directly, as `window.x`.
0 commit comments