πŸ“šΒ Reference


πŸ“œΒ Chapter


Prototype

Object.create()


const parent = {
  sayHi: function() { console.log("μ•ˆλ…•, λ‚˜λŠ” λΆ€λͺ¨μ•Ό!"); }
};

// parentλ₯Ό ν”„λ‘œν† νƒ€μž…μœΌλ‘œ κ°€μ§€λŠ” child 객체 생성
const child = Object.create(parent);

child.sayHi(); // "μ•ˆλ…•, λ‚˜λŠ” λΆ€λͺ¨μ•Ό!" (λΆ€λͺ¨μ˜ λ©”μ„œλ“œλ₯Ό 빌렀 씀)
console.log(child.__proto__ === parent); // true

μ‚¬μš©ν•˜λŠ” 이유


new μ—°μ‚°μžμ™€μ˜ 차이점