Skip to content

Latest commit

ย 

History

History
134 lines (111 loc) ยท 2.38 KB

ch16-๋ฌธ์ œ.md

File metadata and controls

134 lines (111 loc) ยท 2.38 KB

Chapter16 ํ”„๋กœํผํ‹ฐ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ

๐Ÿ“Œ๋ฌธ์ œ1

๋‹ค์Œ ๋ฌธ์žฅ์˜ true or false๋ฅผ ํŒ๋‹จํ•˜์„ธ์š”.

(1) ์กด์žฌํ•˜์ง€ ์•Š๋Š” ํ”„๋กœํผํ‹ฐ๋‚˜ ์ƒ์†๋ฐ›์€ ํ”„๋กœํผํ‹ฐ์— ๋Œ€ํ•œ ํ”„๋กœํผํ‹ฐ ๋””์Šคํฌ๋ฆฝํ„ฐ๋ฅผ ์š”๊ตฌํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
(2) ์ ‘๊ทผ์ž ํ”„๋กœํผํ‹ฐ๋Š” ์ž์ฒด์ ์œผ๋กœ ๊ฐ’(ํ”„๋กœํผํ‹ฐ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ [[Value]])์„ ๊ฐ€์ง„๋‹ค.
(3) [[Configurable]]์˜ ๊ฐ’์ด false์ธ ๊ฒฝ์šฐ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋ฉด ์—๋Ÿฌ ์—†์ด ๋ฌด์‹œํ•œ๋‹ค.

๋‹ต์•ˆ ์ž‘์„ฑ

(1)
(2)
(3)

๐Ÿ“Œ๋ฌธ์ œ2

๋‹ค์Œ ์ฝ”๋“œ์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์ธกํ•˜์„ธ์š”.

const person = { name: "Jing" };
Object.freeze(person);

console.log(Object.getOwnPropertyDescriptors(person)); // (1)

person.age = 23;
console.log(person); // (2)

delete person.name;
console.log(person); // (3)

person.name = "JiEun";
console.log(person); // (4)

Object.defineProperty(person, "name", { configurable: true }); // (5)

๋‹ต์•ˆ ์ž‘์„ฑ

(1)
(2) 
(3) 
(4) 
(5) 

๐Ÿ“Œ๋ฌธ์ œ3

๋‹ค์Œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์“ฐ์‹œ์˜ค

const obj = {
  a : 1,
  b : {
    c : 2
  }
}

Object.freeze(obj);
const descriptor = Object.getOwnPropertyDescriptor(obj, b);
console.log(descriptor);
obj.a = 2;
obj.b.c = 3;
console.log(obj);

๋‹ต์•ˆ ์ž‘์„ฑ


๐Ÿ“Œ๋ฌธ์ œ4

๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ์„ ์–ธ๋ฐฉ์‹(1)๊ณผ defineProperty๋ฐฉ์‹(2)์œผ๋กœ ์„ ์–ธํ–ˆ์„๋–„ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ(writable, enumerable,configurable) ์ •์˜์˜ ์ฐจ์ด์ ์ด ๋ฌด์—‡์ธ์ง€ ์ž‘์„ฑํ•˜์‹œ์˜ค.

๋‹ต์•ˆ ์ž‘์„ฑ


๐Ÿ“Œ๋ฌธ์ œ5

์ถœ๋ ฅ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์ธกํ•˜์„ธ์š”

const obj = {};

Object.defineProperties(obj, {
  firstName: {
    value: "deep",
    writable: true,
    enumerable: true,
    configurable: false,
  },

  lastName: {
    value: "dive",
    writable: true,
    enumerable: true,
    configurable: false,
  },
});


Object.defineProperties(obj, {
  firstName: {
    writable: false,
  },
});

console.log(Object.getOwnPropertyDescriptors(obj)); // (1)

Object.defineProperties(obj, {
  lastName: {
    writable: false,
    enumerable: false,
  },
});

console.log(Object.getOwnPropertyDescriptors(obj)); // (2)

๋‹ต์•ˆ ์ž‘์„ฑ


๐Ÿ“Œ๋ฌธ์ œ6

ํ”„๋กœํผํ‹ฐ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ์˜ ์ข…๋ฅ˜๋กœ Value, Writable, Enumerable, Configurable, Get, Set์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ๊ฐ์— ๋Œ€ํ•ด ๊ฐ„๋‹จํžˆ ์„ค๋ช…ํ•˜์‹œ์˜ค.

๋‹ต์•ˆ ์ž‘์„ฑ

Value :
Writable :
Enumerable :
Configurable :
Get :
Set :