26
CoeeSc" pt getting started 2011.08.08 Outsider

Coffeescript - Getting Started

Embed Size (px)

DESCRIPTION

FRENS의 JavaScript Application Framework 스터디에서 한 발표 자료

Citation preview

Page 1: Coffeescript - Getting Started

CoffeeSc"ptgetting����������� ������������������  started

2011.08.08Outsider

Page 2: Coffeescript - Getting Started

How����������� ������������������  to����������� ������������������  run

Page 3: Coffeescript - Getting Started

in����������� ������������������  Web����������� ������������������  Browser

<script����������� ������������������  type=”coffee-script.js”>

<script����������� ������������������  type=”text/coffeescript”>����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  //����������� ������������������  coffeescript����������� ������������������  code</script>

Page 4: Coffeescript - Getting Started

in����������� ������������������  OSX����������� ������������������  or����������� ������������������  Linux

-����������� ������������������  install����������� ������������������  node.js-����������� ������������������  install����������� ������������������  npm

$����������� ������������������  npm����������� ������������������  install����������� ������������������  -g����������� ������������������  coffee-script$����������� ������������������  coffee

Page 5: Coffeescript - Getting Started

in����������� ������������������  Windows

use����������� ������������������  

CoffeeScript����������� ������������������  CompilerFor����������� ������������������  Windows

https://github.com/alisey/CoffeeScript-Compiler-for-Windows

Page 6: Coffeescript - Getting Started

Function

Page 7: Coffeescript - Getting Started

->

함수를����������� ������������������  정의한다

Page 8: Coffeescript - Getting Started

생략

괄호����������� ������������������  :����������� ������������������  ()

중괄호����������� ������������������  :����������� ������������������  {}

세미콜론����������� ������������������  :����������� ������������������  ;

Page 9: Coffeescript - Getting Started

->����������� ������������������  ‘Hello����������� ������������������  World’

do����������� ������������������  ->����������� ������������������  ‘Hello����������� ������������������  World’

(->����������� ������������������  ‘Hello����������� ������������������  World’)()

Page 10: Coffeescript - Getting Started

함수의����������� ������������������  마지막����������� ������������������  표현식이

����������� ������������������  자동으로����������� ������������������  리턴된다

(return문을����������� ������������������  사용할����������� ������������������  수도����������� ������������������  있다)

Page 11: Coffeescript - Getting Started

이름있는����������� ������������������  함수는����������� ������������������  변수에����������� ������������������  할당

greeting����������� ������������������  =����������� ������������������  ->����������� ������������������  ‘Hello����������� ������������������  World’

Page 12: Coffeescript - Getting Started

파라미터

print����������� ������������������  =����������� ������������������  (msg)����������� ������������������  ->����������� ������������������  msg

Page 13: Coffeescript - Getting Started

Interpolation����������� ������������������  :����������� ������������������  “#{}”

p����������� ������������������  =����������� ������������������  (msg)����������� ������������������  ->����������� ������������������  “hello����������� ������������������  #{msg}”

p����������� ������������������  =����������� ������������������  (msg)����������� ������������������  ->����������� ������������������  ‘hello����������� ������������������  ‘����������� ������������������  +����������� ������������������  msg

Page 14: Coffeescript - Getting Started

+오퍼레이터는����������� ������������������  공백에����������� ������������������  따라����������� ������������������  다르다

‘frends’����������� ������������������  +����������� ������������������  5����������� ������������������  //����������� ������������������  frends5

‘frends’����������� ������������������  +5����������� ������������������  //����������� ������������������  TypeError

Page 15: Coffeescript - Getting Started

Operator

is����������� ������������������  //����������� ������������������  ===isnt����������� ������������������  //����������� ������������������  !==not����������� ������������������  //����������� ������������������  !and����������� ������������������  //����������� ������������������  &&or����������� ������������������  //����������� ������������������  ||

true,����������� ������������������  yes,����������� ������������������  on����������� ������������������  //����������� ������������������  truefalse,����������� ������������������  no,����������� ������������������  off����������� ������������������  //����������� ������������������  false

Page 16: Coffeescript - Getting Started

Contidional

if����������� ������������������  true����������� ������������������  then����������� ������������������  1

1����������� ������������������  if����������� ������������������  true

if����������� ������������������  true����������� ������������������  then����������� ������������������  1����������� ������������������  else����������� ������������������  2

1����������� ������������������  unless����������� ������������������  true

Page 17: Coffeescript - Getting Started

존재여부����������� ������������������  확인

true����������� ������������������  unless����������� ������������������  a?

a����������� ������������������  ?����������� ������������������  b

a����������� ������������������  ?=����������� ������������������  b

값이����������� ������������������  있거나����������� ������������������  undefined나����������� ������������������  null이����������� ������������������  아니면

Page 18: Coffeescript - Getting Started

Scope

Page 19: Coffeescript - Getting Started

변수의����������� ������������������  범위

모든����������� ������������������  함수는����������� ������������������  범위를����������� ������������������  만든다

변수가����������� ������������������  할당된����������� ������������������  최상위범위에서����������� ������������������  존재

범위����������� ������������������  밖에서는����������� ������������������  접근할����������� ������������������  수����������� ������������������  없다

Page 20: Coffeescript - Getting Started

Context

Page 21: Coffeescript - Getting Started

this

@

Page 22: Coffeescript - Getting Started

현재����������� ������������������  컨택스트로����������� ������������������  this����������� ������������������  고정

=>not����������� ������������������  ->

Page 23: Coffeescript - Getting Started

프로퍼티

setName����������� ������������������  =����������� ������������������  (name)����������� ������������������  ->����������� ������������������  @name����������� ������������������  =����������� ������������������  name

setName����������� ������������������  =����������� ������������������  (@name)����������� ������������������  ->

Page 24: Coffeescript - Getting Started

기본값

func����������� ������������������  =����������� ������������������  (a����������� ������������������  =����������� ������������������  true)����������� ������������������  ->����������� ������������������  ...

Page 25: Coffeescript - Getting Started

Splats����������� ������������������  :����������� ������������������  ...

func����������� ������������������  =����������� ������������������  (a,����������� ������������������  b...)����������� ������������������  ->����������� ������������������  

func����������� ������������������  =����������� ������������������  (a,����������� ������������������  b...,����������� ������������������  c)����������� ������������������  ->

func����������� ������������������  -����������� ������������������  (a...,����������� ������������������  b)����������� ������������������  ->

Page 26: Coffeescript - Getting Started

Splats����������� ������������������  :����������� ������������������  ...

user����������� ������������������  =����������� ������������������  [1,����������� ������������������  2,����������� ������������������  3,����������� ������������������  4,����������� ������������������  5]

[a...,����������� ������������������  b]����������� ������������������  =����������� ������������������  user