Skip to content

Commit 000e697

Browse files
committed
[원시값의 메서드] 충돌 해결 (본문)
1 parent 103871a commit 000e697

1 file changed

Lines changed: 2 additions & 18 deletions

File tree

  • 1-js/05-data-types/01-primitives-methods

1-js/05-data-types/01-primitives-methods/article.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,16 @@ john.sayHi(); // 친구야 반갑다!
3939

4040
자바스크립트 창안자(creator)는 다음과 같은 모순적인 상황을 해결해야만 했었습니다.
4141

42-
<<<<<<< HEAD
4342
- 문자열이나 숫자와 같은 원시값을 다루어야 하는 작업이 많은데, 메서드를 사용하면 작업을 수월하게 할 수 있을 것 같다는 생각이 듭니다.
4443
- 그런데 원시값은 가능한 한 빠르고 가벼워야 합니다.
45-
=======
46-
- There are many things one would want to do with a primitive, like a string or a number. It would be great to access them using methods.
47-
- Primitives must be as fast and lightweight as possible.
48-
>>>>>>> upstream/master
4944

5045
조금 어색해 보이지만, 자바스크립트 창안자는 아래와 같은 방법을 사용해 해결책을 모색하였습니다.
5146

5247
1. 원시값은 원시값 그대로 남겨둬 단일 값 형태를 유지합니다.
5348
2. 문자열, 숫자, 불린, 심볼의 메서드와 프로퍼티에 접근할 수 있도록 언어 차원에서 허용합니다.
5449
3. 이를 가능하게 하기 위해, 원시값이 메서드나 프로퍼티에 접근하려 하면 추가 기능을 제공해주는 특수한 객체, "원시 래퍼 객체(object wrapper)"를 만들어 줍니다. 이 객체는 곧 삭제됩니다.
5550

56-
<<<<<<< HEAD
57-
"래퍼 객체"는 원시 타입에 따라 종류가 다양합니다. 각 래퍼 객체는 원시 자료형의 이름을 그대로 차용해, `String`,`Number`,`Boolean`, `Symbol`라고 부릅니다. 래퍼 객체 마다 제공하는 메서드 역시 다릅니다.
58-
=======
59-
The "object wrappers" are different for each primitive type and are called: `String`, `Number`, `Boolean`, `Symbol` and `BigInt`. Thus, they provide different sets of methods.
60-
>>>>>>> upstream/master
51+
"래퍼 객체"는 원시 타입에 따라 종류가 다양합니다. 각 래퍼 객체는 원시 자료형의 이름을 그대로 차용해, `String`,`Number`,`Boolean`, `Symbol`, `BigInt` 라고 부릅니다. 래퍼 객체 마다 제공하는 메서드 역시 다릅니다.
6152

6253
인수로 받은 문자열의 모든 글자를 대문자로 바꿔주는 메서드 [str.toUpperCase()](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)를 예로 들어보겠습니다.
6354

@@ -113,16 +104,9 @@ if (zero) { // 변수 zero는 객체이므로, 조건문이 참이 됩니다.
113104
}
114105
```
115106

116-
<<<<<<< HEAD
117-
그런데, `new`를 붙이지 않고 `String / Number / Boolean`을 사용하는 건 괜찮습니다. `new` 없이 사용하면 상식에 맞게 인수를 원하는 형의 원시값(문자열, 숫자, 불린 값)으로 바꿔줍니다. 아주 유용하죠.
107+
그런데, `new`를 붙이지 않고 `String/Number/Boolean`을 사용하는 건 괜찮습니다. `new` 없이 사용하면 상식에 맞게 인수를 원하는 형의 원시값(문자열, 숫자, 불린 값)으로 바꿔줍니다. 아주 유용하죠.
118108

119109
예시:
120-
=======
121-
On the other hand, using the same functions `String/Number/Boolean` without `new` is totally fine and useful thing. They convert a value to the corresponding type: to a string, a number, or a boolean (primitive).
122-
123-
For example, this is entirely valid:
124-
125-
>>>>>>> upstream/master
126110
```js
127111
let num = Number("123"); // 문자열을 숫자로 바꿔줌
128112
```

0 commit comments

Comments
 (0)