๐ŸŽ‰๐ŸŽ‰ JavaScript์˜ ๊ฐœ์ธ ๋ณ€์ˆ˜ ๋ฐ ๋ฉ”์„œ๋“œ

2984 ๋‹จ์–ด reactvuewebdevjavascript
์ตœ๊ทผ์— new proposal ํด๋ž˜์Šค์— ๊ฐœ์ธ ๋ณ€์ˆ˜์™€ ๋ฉ”์„œ๋“œ๋ฅผ ๋„์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๋„์ž…๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ๋Š” 3๋‹จ๊ณ„์ž…๋‹ˆ๋‹ค.

๋งค์šฐ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ๋ณ€์ˆ˜๋‚˜ ๋ฉ”์†Œ๋“œ ์ด๋ฆ„ ์•ž์— #์„ ๋ถ™์ด๋ฉด private๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

class Person {
  #salary = 100;

  #increaseSalary() {
    this.#salary += 1000;
  }
}

let p1 = new Person();

console.log(p1.#salary); //Error - Private name #salary is not defined
console.log(p1.#increaseSalary); //Error - Private name #increaseSalary is not defined


๐Ÿ‘‰ Live Demo/Playground

๐Ÿ‘‰ Babel 7.2+ ๋ฒ„์ „์—์„œ ์ด ๊ธฐ๋Šฅ์„ ์ฆ‰์‹œ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ‘‰ ์ด babel ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ์ด ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค -
babel-plugin-proposal-private-methods
babel-plugin-proposal-class-properties

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ