UNDERSCORE

underscore.js๋Š” ๊ธฐ๋ณธ JavaScript ๊ฐ์ฒด๋“ค์„ ํ™•์žฅํ•˜์ง€ ์•Š๊ณ , ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์ง€์›ํ•  ์ˆ˜ ์žˆ๋Š” 100๊ฐ€์ง€ ์ด์ƒ์˜ ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ง„ ์œ ์šฉํ•œ JavaScript ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋‹ค.

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ™•์žฅํ•˜์—ฌ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ฑฐ๋‚˜ ์›นํ‘œ์ค€, ํฌ๋กœ์Šค ๋ธŒ๋ผ์šฐ์ง•์— ๋งŽ์ด ์‚ฌ์šฉ๋œ๋‹ค.

context์™€ iteratee

_.each(list, iteratee, [context]);
  • iteratee : ๋ฐ˜๋ณต์„ ์ฒ˜๋ฆฌ ์‹œํ‚ค๋Š” ๋‚ด์šฉ

  • context : context๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ this๋กœ ๋ฐ”์ธ๋”ฉํ•ด์ค€๋‹ค.

var someOtherArray = ["name","patrick","d","w"];

_.each([1, 2, 3], function(num) { 
    console.log( this[num] ); 
}, someOtherArray);

// "patrick"
// "d"
// "w"

๊ทธ๋ฃนํ•จ์ˆ˜

์„ค๋ช…

utilities

์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜

collection

๋ฐฐ์—ด ๋˜๋Š” ๊ฐ์ฒด๋ฅผ ๋‹ค๋ฃจ๋Š” ํ•จ์ˆ˜

arrays

๋ฐฐ์—ด์„ ๋‹ค๋ฃจ๋Š” ํ•จ์ˆ˜

objects

๊ฐ์ฒด๋ฅผ ๋‹ค๋ฃจ๋Š” ํ•จ์ˆ˜

functions

ํ•จ์ˆ˜๋ฅผ ๋‹ค๋ฃจ๋Š” ํ•จ์ˆ˜

underscore.js ๋กœ๋”ฉ ํ›„ ์˜ˆ์•ฝ์–ด _๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. (JQuery์˜ $ ์˜ˆ์•ฝ์–ด์™€ ์œ ์‚ฌ) ์ˆ˜์‹ญ๊ฐ€์ง€ ํ•จ์ˆ˜๋“ค์€ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„๋กœ ๋ถ„๋ฅ˜๋˜์–ด์žˆ๋‹ค.

๊ฐ๊ฐ ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ๋Š” underscore.js ์—์„œ ์ž์„ธํžˆ ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

extend

extend() ๋Š” ๊ฐ์ฒด๋ฅผ ํ™•์žฅํ•˜๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

_.extend(destination, *sources)

source ๊ฐ์ฒด์— ์žˆ๋Š” ๋ชจ๋“  ํ”„๋กœํผํ‹ฐ๋ฅผ destination ๊ฐ์ฒด์— ๋ณต์‚ฌํ•˜๊ณ , destination ๊ฐ์ฒด๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค. source๋Š” ์ˆœ์„œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ, ๋งˆ์ง€๋ง‰ source์˜ ํ”„๋กœํผํ‹ฐ๊ฐ€ ์•ž์˜ ์ธ์ž๋“ค์ด ๊ฐ€์ง„ ๊ฐ™์€ ์ด๋ฆ„์˜ ํ”„๋กœํผํ‹ฐ๋ฅผ ๋ฎ์–ด์“ธ ์ˆ˜ ์žˆ๋‹ค.

์ฐธ์กฐํŽ˜์ด์ง€

Last updated