๐Ÿ” [๋‹จ๊ณจ์งˆ๋ฌธ] - 03. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ด๋ฒคํŠธ ๊ด€๋ฆฌ ๋ฐฉ๋ฒ•? ๋ณดํ†ต ์–ด๋–ค ์‹์œผ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์„ค๊ณ„ํ•ด์•ผ ํ•˜๋Š”์ง€?

์กฐ์ค€ํ˜•ยท2021๋…„ 6์›” 17์ผ
0

interview

๋ชฉ๋ก ๋ณด๊ธฐ
4/20
post-thumbnail
  • ex) ์ด๋ฒคํŠธ ์บก์ณ๋ง & ๋ฒ„๋ธ”๋ง
  • ex) ์ด๋ฒคํŠธ ๋“ฑ๋ก & ํ•ด์ œ
  • ex) ์ด๋ฒคํŠธ ์œ„์ž„ ๋ฐฉ์‹

๐Ÿ’ฌ Answer

๐ŸŒ ์ด๋ฒคํŠธ ์ „ํŒŒ

๐Ÿ‘‰ ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง - Event Bubbling

ํŠน์ • ํ™”๋ฉด ์š”์†Œ์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์ด๋ฒคํŠธ๊ฐ€ ๋” ์ƒ์œ„์˜ ํ™”๋ฉด ์š”์†Œ๋“ค๋กœ ์ „๋‹ฌ๋˜์–ด ๊ฐ€๋Š” ํŠน์„ฑ.
์ฆ‰, ์ž์‹์—์„œ ๋ถ€๋ชจ์—๊ฒŒ ์ „ํŒŒ

๐Ÿ‘‰ ์ด๋ฒคํŠธ ์บก์ณ๋ง - Event Captureing

๋ฒ„๋ธ”๋ง๊ณผ ๋ฐ˜๋Œ€๋กœ ์ง„ํ–‰๋˜๋Š” ์ด๋ฒคํŠธ ์ „ํŒŒ ๋ฐฉ์‹
์ฆ‰, ๋ถ€๋ชจ์—์„œ ์ž์‹์œผ๋กœ ์ „ํŒŒ

โ— event.stopPropagation()์„ ํ•˜๊ฒŒ๋˜๋ฉด ์ด๋ฒคํŠธ์˜ ๋ฒ„๋ธ”๋ง์„ ๋ง‰์Œ.
Javascript30 - 25๋ฒˆ์งธ ๊ฐ•์˜์—์„œ ์‹ค์Šต.
์ฐธ๊ณ ๋งํฌ

๐ŸŒ ์ด๋ฒคํŠธ ์œ„์ž„ - Event Delegation

์ด๋ฒคํŠธ ์œ„์ž„์„ ํ•œ ๋ฌธ์žฅ์œผ๋กœ ์ •๋ฆฌํ•˜์ž๋ฉด,
ํ•˜์œ„์—์„œ ๊ฐ๊ฐ ์ด๋ฒคํŠธ๋ฅผ ๋ถ™์ด์ง€ ์•Š๊ณ , ์ƒ์œ„ ์š”์†Œ์—์„œ ํ•˜์œ„ ์š”์†Œ์˜ ์ด๋ฒคํŠธ๋ฅผ ์ œ์–ดํ•˜๋Š” ๋ฐฉ์‹.

๐Ÿ‘‰ ์ด๋ฒคํŠธ ์œ„์ž„ Example

ํ•˜์œ„์š”์†Œ๋งˆ๋‹ค ์ด๋ฒคํŠธ๋ฅผ ๋‹ฌ ๊ฒฝ์šฐ.
๋งŒ์•ฝ ์š”์†Œ๋ฅผ ๋ชจ๋‘ ๊ฐ€์ ธ์™€ ์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ๊ทธ ๋ฐ‘์—์„œ ์ƒˆ๋กœ์šด ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•  ๋•Œ.
=> ์ƒˆ๋กœ์šด ์š”์†Œ์—๋Š” ์ด๋ฒคํŠธ๊ฐ€ ๋‹ฌ๋ฆฌ์ง€ ์•Š๋Š”๋‹ค.

โ“ Why
์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•  ๋‹น์‹œ์—๋Š” ์ฒ˜์Œ ์š”์†Œ๋“ค๋งŒ ๊ฐ€์ ธ์™€์„œ ์ถ”๊ฐ€ํ•˜๊ธฐ ๋•Œ๋ฌธ์—,
์ƒˆ๋กœ์šด ์š”์†Œ์—๋Š” ์ด๋ฒคํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์ง€์•Š์Œ.

โ“ How
ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์€?
=> ์š”์†Œ๋“ค์„ ๊ฐ์‹ธ๋Š” ์ƒ์œ„์š”์†Œ์— ์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•˜์œ„์š”์†Œ์˜ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์ง€ํ•œ๋‹ค.

๐Ÿ“˜ ์ฐธ๊ณ 

https://joshua1988.github.io/web-development/javascript/event-propagation-delegation/
https://github.com/JuneHyung/JavaScript30/tree/master/25%20-%20Event%20Capture%2C%20Propagation%2C%20Bubbling%20and%20Once

profile
๊นƒํ—ˆ๋ธŒ : github.com/JuneHyung

0๊ฐœ์˜ ๋Œ“๊ธ€