Coffeescript - Getting Started
-
Upload
jeonghoon-byun -
Category
Technology
-
view
2.896 -
download
0
description
Transcript of Coffeescript - Getting Started
CoffeeSc"ptgetting����������� ������������������ started
2011.08.08Outsider
How����������� ������������������ to����������� ������������������ run
in����������� ������������������ Web����������� ������������������ Browser
<script����������� ������������������ type=”coffee-script.js”>
<script����������� ������������������ type=”text/coffeescript”>����������� ������������������ ����������� ������������������ ����������� ������������������ ����������� ������������������ //����������� ������������������ coffeescript����������� ������������������ code</script>
in����������� ������������������ OSX����������� ������������������ or����������� ������������������ Linux
-����������� ������������������ install����������� ������������������ node.js-����������� ������������������ install����������� ������������������ npm
$����������� ������������������ npm����������� ������������������ install����������� ������������������ -g����������� ������������������ coffee-script$����������� ������������������ coffee
in����������� ������������������ Windows
use����������� ������������������
CoffeeScript����������� ������������������ CompilerFor����������� ������������������ Windows
https://github.com/alisey/CoffeeScript-Compiler-for-Windows
Function
->
함수를����������� ������������������ 정의한다
생략
괄호����������� ������������������ :����������� ������������������ ()
중괄호����������� ������������������ :����������� ������������������ {}
세미콜론����������� ������������������ :����������� ������������������ ;
->����������� ������������������ ‘Hello����������� ������������������ World’
do����������� ������������������ ->����������� ������������������ ‘Hello����������� ������������������ World’
(->����������� ������������������ ‘Hello����������� ������������������ World’)()
함수의����������� ������������������ 마지막����������� ������������������ 표현식이
����������� ������������������ 자동으로����������� ������������������ 리턴된다
(return문을����������� ������������������ 사용할����������� ������������������ 수도����������� ������������������ 있다)
이름있는����������� ������������������ 함수는����������� ������������������ 변수에����������� ������������������ 할당
greeting����������� ������������������ =����������� ������������������ ->����������� ������������������ ‘Hello����������� ������������������ World’
파라미터
print����������� ������������������ =����������� ������������������ (msg)����������� ������������������ ->����������� ������������������ msg
Interpolation����������� ������������������ :����������� ������������������ “#{}”
p����������� ������������������ =����������� ������������������ (msg)����������� ������������������ ->����������� ������������������ “hello����������� ������������������ #{msg}”
p����������� ������������������ =����������� ������������������ (msg)����������� ������������������ ->����������� ������������������ ‘hello����������� ������������������ ‘����������� ������������������ +����������� ������������������ msg
+오퍼레이터는����������� ������������������ 공백에����������� ������������������ 따라����������� ������������������ 다르다
‘frends’����������� ������������������ +����������� ������������������ 5����������� ������������������ //����������� ������������������ frends5
‘frends’����������� ������������������ +5����������� ������������������ //����������� ������������������ TypeError
Operator
is����������� ������������������ //����������� ������������������ ===isnt����������� ������������������ //����������� ������������������ !==not����������� ������������������ //����������� ������������������ !and����������� ������������������ //����������� ������������������ &&or����������� ������������������ //����������� ������������������ ||
true,����������� ������������������ yes,����������� ������������������ on����������� ������������������ //����������� ������������������ truefalse,����������� ������������������ no,����������� ������������������ off����������� ������������������ //����������� ������������������ false
Contidional
if����������� ������������������ true����������� ������������������ then����������� ������������������ 1
1����������� ������������������ if����������� ������������������ true
if����������� ������������������ true����������� ������������������ then����������� ������������������ 1����������� ������������������ else����������� ������������������ 2
1����������� ������������������ unless����������� ������������������ true
존재여부����������� ������������������ 확인
true����������� ������������������ unless����������� ������������������ a?
a����������� ������������������ ?����������� ������������������ b
a����������� ������������������ ?=����������� ������������������ b
값이����������� ������������������ 있거나����������� ������������������ undefined나����������� ������������������ null이����������� ������������������ 아니면
Scope
변수의����������� ������������������ 범위
모든����������� ������������������ 함수는����������� ������������������ 범위를����������� ������������������ 만든다
변수가����������� ������������������ 할당된����������� ������������������ 최상위범위에서����������� ������������������ 존재
범위����������� ������������������ 밖에서는����������� ������������������ 접근할����������� ������������������ 수����������� ������������������ 없다
Context
this
@
현재����������� ������������������ 컨택스트로����������� ������������������ this����������� ������������������ 고정
=>not����������� ������������������ ->
프로퍼티
setName����������� ������������������ =����������� ������������������ (name)����������� ������������������ ->����������� ������������������ @name����������� ������������������ =����������� ������������������ name
setName����������� ������������������ =����������� ������������������ (@name)����������� ������������������ ->
기본값
func����������� ������������������ =����������� ������������������ (a����������� ������������������ =����������� ������������������ true)����������� ������������������ ->����������� ������������������ ...
Splats����������� ������������������ :����������� ������������������ ...
func����������� ������������������ =����������� ������������������ (a,����������� ������������������ b...)����������� ������������������ ->����������� ������������������
func����������� ������������������ =����������� ������������������ (a,����������� ������������������ b...,����������� ������������������ c)����������� ������������������ ->
func����������� ������������������ -����������� ������������������ (a...,����������� ������������������ b)����������� ������������������ ->
Splats����������� ������������������ :����������� ������������������ ...
user����������� ������������������ =����������� ������������������ [1,����������� ������������������ 2,����������� ������������������ 3,����������� ������������������ 4,����������� ������������������ 5]
[a...,����������� ������������������ b]����������� ������������������ =����������� ������������������ user