Skip to content
croquiscom edited this page Aug 23, 2012 · 3 revisions

CoffeeScript๋Š” JavaScript ์†Œ์Šค๋กœ ์ปดํŒŒ์ผ ๋˜๋Š” ์–ธ์–ด๋กœ, Ruby, Python, Haskell ๋“ฑ์—์„œ ์˜ํ–ฅ์„ ๋ฐ›์€ ๋งŽ์€ ์„คํƒ• ๋ฌธ๋ฒ•์„ ํ†ตํ•ด JavaScript๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ณ  ์ฝ๊ธฐ ํŽธํ•˜๊ฒŒ ๋งŒ๋“ค์—ˆ๋‹ค.

JavaScript๋กœ ์‚ฌ์ „ ์ปดํŒŒ์ผ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์‹คํ–‰ ์‹œ๊ฐ„์— ์„ฑ๋Šฅ ์ €ํ•˜๊ฐ€ ์—†๊ณ , ์ฝ์„ ์ˆ˜ ์žˆ๋Š” JavaScript๋ฅผ ๊ฒฐ๊ณผ๋ฌผ๋กœ ์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ๋””๋ฒ„๊น…์— ํฐ ์˜ํ–ฅ๋„ ์—†๋‹ค.

ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์‹ค์‹œ๊ฐ„ ์ปดํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ๋‹ค์Œ์€ HTML์— CoffeeScript๋ฅผ ์ง์ ‘ ๋„ฃ์€ ์˜ˆ์ด๋‹ค.

<script type="text/coffeescript">
list = [1, 2, 3, 4, 5]
cube = (x) -> x * x * x
cubes = (cube num for num in list)
alert cubes
</script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.2.0/coffee-script.min.js"></script>

Vim ํ”Œ๋Ÿฌ๊ทธ์ธ

์„ค์น˜

https://github.com/kchmck/vim-coffee-script ์—์„œ ํŒŒ์ผ์„ ๋ฐ›์•„ ~/.vim ๋””๋ ‰ํ† ๋ฆฌ์— ํ‘ผ๋‹ค. ์—†์œผ๋ฉด ์ƒˆ๋กœ ๋งŒ๋“ค๋ฉด ๋˜๊ณ  ์••์ถ•์„ ํ’€๋ฉด ~/.vim/syntax ๋“ฑ์˜ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์ƒ๊ธด๋‹ค.

์„ค์ •

.coffee ํŒŒ์ผ์„ ์ฝ์œผ๋ฉด syntax highlight ๋Š” ์ž๋™์œผ๋กœ ๋˜์ง€๋งŒ, ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ช…๋ น์–ด๋ฅผ ์“ฐ๋ ค๋ฉด ~/.vimrc ํŒŒ์ผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์„ค์ •์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค.

filetype plugin on

์‚ฌ์šฉ๋ฒ•

VIM ๋ช…๋ น์–ด๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฃผ๋ฉด ์ฐฝ์ด ๋ฐ˜์œผ๋กœ ๋‚˜๋Šฌ์–ด ํ•œ์ชฝ์— ๋ณ€ํ™˜๋œ JavaScript ํŒŒ์ผ์ด ํ‘œ์‹œ๋œ๋‹ค. ๋ณ€ํ™˜๋œ ๋‚ด์šฉ์€ ์›๋ณธ ์†Œ์Šค๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค ์ž๋™์œผ๋กœ ๊ฐฑ์‹ ๋œ๋‹ค.

:CoffeeCompile watch vert

์ฐธ๊ณ