javascript

커피스크립트 문법 #2

단순대왕 2014. 9. 22. 15:36

객체

예)

person = 

name: "RintIanTta"

language: "JavaScript"

region: "Seoul, KOREA"

console.log person.name, person.language, person.region

괄호와 쉼표는 필요 없지만 반드시 들여쓰기 해야합니다.


범위 객체

[0..2]     => [0,1,2]      // 2 포함

[0...2]    => [0,1]        // 2 포함하지 않음


반복문

예)

for i in [0...10]

console.log "#{i} - Loop"

예)

for i in [9..0]

console.log "#{i} - Loop"

예)

for i in [0..10] by 2

console.log "#{i" - Loop"

예)

for key, value of person

console.log "#{key} - #{value}"


반복 조합 배열

반복 조합 배열은 반복문으로 새로운 배열을 쉽게 생성합니다.

예)

array = for key, value of person

"#{key} - #{value}"

console.log array

예)

array = []

for i in [0..100]

array.push Math.round(Math.random() * 100)

array = for item in array when item % 2 is 0

console.log array