
ํ๋กํ ํ์ ์ฒด์ธ ํ๋กํ ํ์ ์ฒด์ธ์ด๋? ์๋ฐ์คํฌ๋ฆฝํธ๋ ๊ฐ์ฒด์ ์์ฑ๊ณผ ๋ฉ์๋์ ์ ๊ทผํ ๋ ํด๋น ๊ฐ์ฒด์ ์ ๊ทผํ๊ณ ์ ํ๋ ์์ฑ๊ณผ ๋ฉ์๋๊ฐ ์์ ๊ฒฝ์ฐ ๋ถ๋ชจ ์ญํ ์ ํ๋ ํ๋กํ ํ์ ์ ์์ฑ๊ณผ ๋ฉ์๋๋ฅผ ์์ฐจ์ ์ผ๋ก ๊ฒ์ํ๋ค. ์ด๊ฒ์ ํ๋กํ ํ์ ์ฒด์ธ์ด๋ผ๊ณ ํ๋ค. class Person { constructor(name, favorite) { this.name = name; this.favorite = favorite; } like() { console.log(`${this.name}์ ${this.favorite}์ ์ข์ํฉ๋๋ค.`); } } const subin = new Person('์๋น', '์ดํผ์น'); subin์ Person์ ์ํด ์์ฑ๋ ์ธ์คํด์ค์ด๊ธฐ ๋๋ฌธ์ Person.prototype์ ๋ฉ์๋์ธ like()๋ฅผ..

ํ๋กํ ํ์ ํ๋กํ ํ์ ์ด๋? ํ๋กํ ํ์ ์ ์ํ ๊ฐ์ฒด๋ก, ์ด๋ค ๊ฐ์ฒด์ ๋ถ๋ชจ ๊ฐ์ฒด ์ญํ ์ ํ๋ ๊ฐ์ฒด์ด๋ค. โ๏ธ .prototype์ __proto__ prototype ์์ฑ์ ํจ์ ๊ฐ์ฒด๋ง์ด ์์ ํ๋ ์์ฑ์ผ๋ก ์์ฑ์๊ฐ ์์ฑํ ์ธ์คํด์ค์ ํ๋กํ ํ์ ์, __proto__ ์ ๊ทผ์ ์์ฑ์ ์์ ์ ํ๋กํ ํ์ ์ ๊ฐ์ ์ ์ผ๋ก ์ ๊ทผํ ์ ์๋ ์์ฑ์ ๊ฐ๋ฆฌํจ๋ค. prototype์ ์์ฑ์ ํจ์๊ฐ, __proto__๋ ๋ชจ๋ ๊ฐ์ฒด๊ฐ ์ฌ์ฉ ์ฃผ์ฒด์ด๋ค. ๊ตฌ๋ถ ์์ ๊ฐ ์ฌ์ฉ ์ฃผ์ฒด ์ฌ์ฉ ๋ชฉ์ prototype constructor ํ๋กํ ํ์ ์ ์ฐธ์กฐ ์์ฑ์ ์์ฑ์ ํจ์๊ฐ ์์ฑํ ์ธ์คํด์ค์ ํ๋กํ ํ์ ์ ํ ๋น __proto__ ๋ชจ๋ ๊ฐ์ฒด ํ๋กํ ํ์ ์ ์ฐธ์กฐ ๋ชจ๋ ๊ฐ์ฒด ๊ฐ์ฒด๊ฐ ์์ ์ ํ๋กํ ํ์ ์ ์ ๊ทผ class Person { constructor(..

๊ฐ์ฒด ์งํฅ ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ์ด๋? ํ๋์ ์ฒญ์ฌ์ง์ ๋ง๋ค๊ณ ๊ทธ ์ฒญ์ฌ์ง์ ๋ฐํ์ผ๋ก, ์ฆ ์๋ฐ์คํฌ๋ฆฝํธ์์๋ class๋ฅผ ๋ฐํ์ผ๋ก ํ๋ ํ๋์ ๊ฐ์ฒด, ์ฆ instance๋ฅผ ๋ง๋๋ ํ๋ก๊ทธ๋๋ฐ ํจํด์ ์๋ฏธํ๋ค. โ๏ธ ํด๋์ค์ ์ธ์คํด์ค ํด๋์ค๋ ์์ฑ๊ณผ ๋ฉ์๋๋ฅผ ์ ์ํ๋ ๊ณต๊ฐ์ด๊ณ ์ธ์คํด์ค๋ ํด๋์ค์์ ์ ์๋ ์ ๋ณด๋๋ฅผ ๊ฐ์ ธ์ ์ด์ฉํ๋ ๊ฐ์ฒด์ด๋ค. ์์ฑ์ ํด๋์ค์ ํฌํจ๋๋ ๋ณ์๋ฅผ ์๋ฏธํ๊ณ , ๋ฉ์๋๋ ํด๋์ค์ ํฌํจ๋๋ ํจ์๋ฅผ ์๋ฏธํ๋ค. ํด๋์ค๋ฅผ ์ ์ํ๋ ๋ฐ์๋ 2๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค. ํจ์๋ก ์ ์ (ES5 ๋ฌธ๋ฒ) function Introduce(name, age, favorite) { // ์ธ์คํด์ค ๋ง๋ค์ด์ง ๋ ์คํ๋๋ ์ฝ๋ } class ํค์๋๋ก ์ ์ (ES6 ๋ฌธ๋ฒ) class Introduce { constructor(..