Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: Map.prototype.get(), has() 추가 #11171

Merged
merged 2 commits into from Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,70 @@
---
title: Map.prototype.get()
slug: Web/JavaScript/Reference/Global_Objects/Map/get
---

{{JSRef}}

**`get()`** 메서드는 `Map` 객체에서 특정 요소를 반환합니다. 만약 주어진 키와 관련된 값이 객체라면 해당 객체에 대한
참조만 가져오고, 해당 객체에 대한 모든 변경은 `Map` 내에서 효율적으로 수정됩니다.

{{EmbedInteractiveExample("pages/js/map-prototype-get.html")}}

## 구문

```js-nolint
get(key)
```

### 매개변수

- `key`
- : `Map` 객체에서 반환받을 요소의 키

### 반환 값

명시된 키와 연관된 요소 혹은 `Map` 객체에서 해당 키를 찾을 수 없는 경우 {{jsxref("undefined")}}.

## 예제

### get() 사용하기

```js
const myMap = new Map();
myMap.set('bar', 'foo');

console.log(myMap.get('bar')); // Returns "foo"
console.log(myMap.get('baz')); // Returns undefined
```

### get()을 사용하여 객체에 대한 참조 검색

```js
const arr = [];
const myMap = new Map();

myMap.set('bar', arr);

myMap.get('bar').push('foo');

console.log(arr); // ["foo"]
console.log(myMap.get('bar')); // ["foo"]
```

맵이 원본 객체에 대한 참조만 보유하고 있다는 것은 해당 객체는 예측하지 못한 메모리 문제가 발생할 소지가 있는 가비지 수집이 되지 않음을
의미합니다. 만약 맵에 저장되어 있는 객체가 원본 객체와 동일한 수명을 가지게 하려면 {{jsxref("WeakMap")}}을 고려하시기
바랍니다.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
맵이 원본 객체에 대한 참조만 보유하고 있다는 것은 해당 객체는 예측하지 못한 메모리 문제가 발생할 소지가 있는 가비지 수집이 되지 않음을
의미합니다. 만약 맵에 저장되어 있는 객체가 원본 객체와 동일한 수명을 가지게 하려면 {{jsxref("WeakMap")}}을 고려하시기
바랍니다.
맵이 원본 객체에 대한 참조만 보유하고 있다는 것은 오브젝트가 가비지 콜렉팅되지 않을 수 있으며 이로 인해예측하지 못한 메모리 이슈가 일어날 수 있음을 의미합니다. 만약 맵에 저장되어 있는 객체가 원본 객체와 동일한 수명을 가지게 하려면 {{jsxref("WeakMap")}}을 고려하시기 바랍니다.

안녕하세요! @wisedog 님. 다음 문장에 대한 번역 제안을 드립니다.

Note that the map holding a reference to the original object effectively means the object cannot be garbage-collected, which may lead to unexpected memory issues.

Copy link
Contributor Author

@wisedog wisedog Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중간에 끊은건 좋은 제안입니다.

다만 제안주신 내용 중 아래 내용을 한 번 살펴보시면 어떨까 합니다.

(제안주신 내용) -> (다시 제안드리는 내용)
오브젝트 -> 해당 객체
가비지 콜렉팅 -> 가비지 콜렉션 혹은 쓰레기 수집
메모리 이슈 -> 메모리 문제

독자가 이해하는데 크게 문제 없으면 영어보다는 한글로 적고자 합니다만, 가비지 콜렉팅은... 현업에서는 전자를 주로 쓰긴하던데 쓰려면 가비지 콜렉션으로 하던가 쓰레기 수집이 좋지 않을까 싶습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 제안 주신 부분 모두 좋습니다 :) 자주 사용하는 표현을 반영하여 쓰레기 수집보다는 가비지 콜렉션이 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다. 좋은 리뷰 감사합니다!


## 명세서

{{Specifications}}

## 브라우저 호환성

{{Compat}}

## 같이 보기

- {{jsxref("Map")}}
- {{jsxref("Map.prototype.set()")}}
- {{jsxref("Map.prototype.has()")}}
@@ -0,0 +1,51 @@
---
title: Map.prototype.has()
slug: Web/JavaScript/Reference/Global_Objects/Map/has
---

{{JSRef}}

**`has()`** 메서드는 주어진 키에 해당하는 요소가 존재 여부를 가리키는 불리언 값을 반환합니다.

{{EmbedInteractiveExample("pages/js/map-prototype-has.html")}}

## 구문

```js-nolint
has(key)
```

### 매개변수

- `key`
- : `Map` 객체에서 존재를 확인할 요소의 키

### 반환 값

만약 주어진 키에 해당하는 요소가 `Map`객체에 존재한다면 `true`, 그렇지 않으면 `false`

## 예제

### has() 사용하기

```js
const myMap = new Map();
myMap.set("bar", "foo");

console.log(myMap.has("bar")); // true
console.log(myMap.has("baz")); // false
```

## 명세서

{{Specifications}}

## 브라우저 호환성

{{Compat}}

## 같이 보기

- {{jsxref("Map")}}
- {{jsxref("Map.prototype.set()")}}
- {{jsxref("Map.prototype.get()")}}