๊ด€๋ฆฌ ๋ฉ”๋‰ด

๋ชฉ๋ก์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ณ‘ํ•ฉ (2)

Hey Tech

[JavaScript] ๊ฐ์ฒด ๋ณ‘ํ•ฉ ๋ฐฉ๋ฒ•(Objet.assign ํ•จ์ˆ˜, ์ „๊ฐœ์—ฐ์‚ฐ์ž)

๐Ÿ’ก ๋ชฉํ‘œ JavaScript์—์„œ ๊ฐ์ฒด ๋ณ‘ํ•ฉ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ํ•™์Šตํ•œ๋‹ค. ๋ชฉ์ฐจ 1. Object.assign() ํ•จ์ˆ˜ 2. ์ „๊ฐœ์—ฐ์‚ฐ์ž 3. ์ผ๋ฐ˜ ํ•จ์ˆ˜ ์ •์˜ ๋“ค์–ด๊ฐ€๋ฉฐ ๊ฐ์ฒด๋ฅผ ๋ณ‘ํ•ฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ 3๊ฐ€์ง€๊ฐ€ ์žˆ์œผ๋ฉฐ ๊ฐ๊ฐ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ €, 3๊ฐœ ๊ฐ์ฒด๋ฅผ ์˜ˆ์‹œ๋กœ ์ •์˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. let obj1 = { a: 10, b: 20, c: 30 } let obj2 = { c: 30, d: 40, } let obj3 = { c: 770, d: 477, } 1. Objet.assign() ํ•จ์ˆ˜ ํ•จ์ˆ˜ ์›ํ˜• Object.assign(๊ฐ์ฒด1, ๊ฐ์ฒด2, ๊ฐ์ฒด3, ... , ๊ฐ์ฒด N); Object ๊ฐ์ฒด ๋‚ด assign ํ•จ์ˆ˜๋Š” ๊ฐ์ฒด์˜ ์›์†Œ๋ฅผ ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๊ณ  ๋ณ‘ํ•ฉํ•ฉ๋‹ˆ๋‹ค. ๋‹จ, ์ค‘๋ณต๋˜๋Š” ์›์†Œ๋Š” ๋‚˜์ค‘์— ๋ณ‘ํ•ฉํ•˜๋Š” ๊ฐ์ฒด์˜ ์›์†Œ๋กœ ์ตœ์ข… ๋ณ‘ํ•ฉํ•ฉ..

SW ๊ฐœ๋ฐœ/Vanilla JS 2021. 12. 3. 00:01