Prototype pattern - amorfati0310/javascript-vm GitHub Wiki

Prototype pattern

ν”„λ‘œν† νƒ€μž… 기법 클래슀둜 λ§Œλ“€κΈ° 전에 function -> new μƒμ„±μž ν•¨μˆ˜λ₯Ό λ§Œλ“€μ—ˆμ„ λ•Œ 같은 λ©”μ†Œλ“œλ₯Ό 같은 λ©”λͺ¨λ¦¬μ— μ°Έμ‘°ν•΄μ£ΌκΈ° μœ„ν•΄μ„œ λ©”μ†Œλ“œλ“€μ€ ν”„λ‘œν† νƒ€μž…μœΌλ‘œ μ„ μ–Έν•˜λŠ” 기법

  • es6 클래슀λ₯Ό μ“°λ©΄ μžλ™μ μœΌλ‘œ λ©”μ†Œλ“œλŠ” ν”„λ‘œν† νƒ€μž…μ— λ‹΄κΈ΄λ‹€!

function Health(){
}
Health.prototype.showHealth = fucntion(){

}

Prototype κ³Ό new ν‚€μ›Œλ“œ __proto λΌλŠ” 속성이 μžˆμŠ΅λ‹ˆλ‹€. -> μ»¨μŠ€νŠΈλŸ­ν„°μ™€ prototype λ©”μ†Œλ“œλ“€μ„ μ†μ„±μ—μ„œ κ°€μ§€κ³  μžˆλ‹€.

ν”„λ‘œν† νƒ€μž…μ„ μ°Ύμ•„λ³΄λ‹ˆ ν”„λ‘œκ·Έλž˜λ°μ— js만 μ μš©λ˜λŠ” νŒ¨ν„΄μ΄ μ•„λ‹ˆκ³  기쑴에 λ‚˜μ™€ 있던 νŒ¨ν„΄μ˜€λ‹€.