๐ก ๋์ ๋ชจ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํต์ฌ ๊ฐ์ด๋๋ฅผ ์ฝ๊ณ ์ ๋ฆฌํฉ๋๋ค.
11.1 ์ฌ๋ฒ์ ๊ณ ์ ์ฑ
์ฌ๋ฒ์ ES6์ ์ฒ์ ์ถ๊ฐ๋ ์์ ์๋ฃํ์ผ๋ก ํญ์ ๊ณ ์ ์ฑ์ ์ง๋
const me = Symbol("Alberto");
console.log(me);
// Symbol(Alberto)
const clone = Symbol("Alberto");
console.log(clone);
// Symbol(Alberto)
console.log(me == clone);
// false
console.log(me === clone);
// false
11.2 ๊ฐ์ฒด ์์ฑ์ ๋ํ ์๋ณ์
๊ฐ์ฒด ์์ฑ์ ์๋ณ์๋ก ์ฌ์ฉ ๊ฐ๋ฅ
๋์ผํ ์์ฑ๋ช ์ด ๊ฐ๊ฐ ๊ณ ์ ํ๊ฒ ์กด์ฌํด์ผ ํ ๊ฒฝ์ฐ ์ฌ์ฉ ๊ฐ๋ฅ
const office = {
[Symbol("Tom")]: "CEO",
[Symbol("Mark")]: "CTO",
[Symbol("Mark")]: "CIO",
};
for (person in office) {
console.log(person);
}
// undefined
11.3 ์ฌ๋ฒ์ ๋ฐ๋ณต
์ฌ๋ฒ์ ์ด๊ฑฐ๊ฐ ๋ถ๊ฐ๋ฅํ๋ฏ๋ก ์ฌ๋ฒ์ ๋ํ ๋ฐ๋ณต์ ์ํด์ Object.getOwnPropertySymbols()
๋ฅผ ์ฌ์ฉ
const office = {
[Symbol("Tom")] : "CEO",
[Symbol("Mark")] : "CTO",
[Symbol("Mark")] : "CIO",
};
const symbols = Object.getOwnPropertySymbols(office);
console.log(symbols);
// 0: Symbol(Tom)
// 1: Symbol(Mark)
// 2: Symbol(Mark)
// length: 3
// ๋ฐฐ์ด์ ์ป์ ํ ์์ฑ์ ์ ๊ทผํ๋ ค๋ฉด map ์ฌ์ฉ
const office = {
[Symbol("Tom")] : "CEO",
[Symbol("Mark")] : "CTO",
[Symbol("Mark")] : "CIO",
};
const symbols = Object.getOwnPropertySymbols(office);
const value = symbols.map(symbol => office[symbol]);
console.log(value);
// 0: "CEO"
// 1: "CTO"
// 2: "CIO"
// length: 3
'Tech > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Swiper ์์ญ ๋๋น๊ฐ ๋์ ์ผ๋ก ๋ฐ๋ ๊ฒฝ์ฐ, ๋ด๋ถ์ ์ฝํ ์ธ ๋๋น ์ ๋ฐ์ดํธํ๊ธฐ (0) | 2023.08.30 |
---|---|
Chapter 12: Classes (0) | 2022.01.26 |
Chapter 10: ๊ฐ์ฒด ๋ฆฌํฐ๋ด (Object literal upgrades) (0) | 2022.01.24 |
Chapter 09: Spread์ Rest (Spread operator and rest parameters) (0) | 2022.01.23 |
Chapter 08: ๋ฐฐ์ด ๋ฉ์๋ (Array improvements) (0) | 2022.01.22 |