
νλ‘μΈμ€ / μ°λ λ / λ©ν°μ°λ λ© / μλ°μ€ν¬λ¦½νΈ μμ§ / call stack / event loop / render sequence / λΈλΌμ°μ κ° μ½λλ₯Ό μ€ννλ κ³Όμ / task queueμ microtask queueμ μ°¨μ΄ / requestAnimationFrame() / λλ²κΉ tips (κ°λ°μ λꡬ source ν νμ© λ²)
λ―Έλ κ²μ μ΅μ’ μμ±
λ―Έλ κ²μ μ΅μ’ μμ±
Object.freeze()λ₯Ό μ΄μ©ν΄ μΈμλ‘ λ¬Έμμ΄ carrotκ³Ό bugκ° λ€μ΄κ°λ λΆλΆμ μμ ν¨
export const ItemType = Object.freeze({
carrot: 'carrot',
bug: 'bug'
});
onItemClick (item) {
if (!this.started) {
return;
}
if (item === ItemType.carrot) { // 'carrot'μ μμ
this.showGameLimit(--this.limit);
if (this.limit === 0) {
this.stop(Reason.win);
}
} else if (item === ItemType.bug) { // 'bug'λ₯Ό μμ
this.stop(Reason.lose);
}
}
onFieldClick (event) {
const target = event.target;
if (target.matches('.carrot')) {
target.remove();
this.callBack && this.callBack(ItemType.carrot); // 'carrot'μ μμ
playSound(carrotSound);
} else if (target.matches('.bug')) {
this.callBack && this.callBack(ItemType.bug); // 'bug'λ₯Ό μμ
}
}
κ°μ μ μκΆ λ¬Έμ λ‘ μΈν΄ λ°°μ΄ κ²κ³Ό νκΈ° λ΄μ©μ μΊ‘μ³ν΄ 첨λΆν¨
μλ³Έμ κΉνλΈ private μ μ₯μμ μ¬λ¦Ό
![[TIL] 211007 νκΈ° λ΄μ©](https://velog.velcdn.com/images%2Fleesyong%2Fpost%2F4400dcc5-d1a7-4df7-898d-fa178c6b6caa%2F4.%20%EC%9D%B4%EB%B2%A4%ED%8A%B8%20%EB%A3%A8%ED%94%84%20-%20OneNote%202021-10-08%20%EC%98%A4%EC%A0%84%2012_51_47.png)