coffeescript

30
CoffeeScript 전용우 12년 11월 29일 목요일

Upload: yongwoo-jeon

Post on 15-Jan-2015

516 views

Category:

Documents


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: CoffeeScript

CoffeeScript전용우

12년 11월 29일 목요일

Page 2: CoffeeScript

CoffeeScript?

12년 11월 29일 목요일

Page 3: CoffeeScript

12년 11월 29일 목요일

Page 4: CoffeeScript

Feature

12년 11월 29일 목요일

Page 5: CoffeeScript

no brace, semicolonif(true){

alert(1);

}else{

alert(2);

}

if true

alert 1

else

alert 2

12년 11월 29일 목요일

Page 6: CoffeeScript

Functionvar square = function(x){

return x * x;

}

square = (x) -> x * x

12년 11월 29일 목요일

Page 7: CoffeeScript

Objectvar bareObj = {

“name” : “전용우”,

“id” : “mixed”

};

bareObj =

name : “전용우”

id : “mixed”

12년 11월 29일 목요일

Page 8: CoffeeScript

Conditional Assignmentvar date;if(friday){

date = sue;}else{

date = jill;}

---------------------------------------------------date = if friday then sue else jill

12년 11월 29일 목요일

Page 9: CoffeeScript

Loops/comprehensions

foods = ['broccoli', 'spinach', 'chocolate']eat food for food in foods when food isnt 'chocolate'

12년 11월 29일 목요일

Page 10: CoffeeScript

Splats

joinArgs = (first, middles..., last) -> parts = [] if first? parts.push first.toUpperCase() for middle in middles parts.push middle.toLowerCase() if last? parts.push last.toUpperCase()

console.log joinArgs("a"); # Aconsole.log joinArgs("a", "b"); #ABconsole.log joinArgs("a", "B", "C", "d"); #AbcD

12년 11월 29일 목요일

Page 11: CoffeeScript

String Interpolationsquare = (x) -> x*x

id = "mixed"

str = "#{id} is #{square()}"

12년 11월 29일 목요일

Page 12: CoffeeScript

Destructuring Assignment

theBait = 1000theSwitch = 0

[theBait, theSwitch] = [theSwitch, theBait]

12년 11월 29일 목요일

Page 13: CoffeeScript

Function binding

Account = (customer, cart) -> @customer = customer @cart = cart

$('.shopping_cart').bind 'click', (event) => @customer.purchase @cart

12년 11월 29일 목요일

Page 14: CoffeeScript

장점

12년 11월 29일 목요일

Page 15: CoffeeScript

"true" == true // true

"true" === true // false

"0" == false // true

"0" == 0 // true

0 === false // false

"" == false // true

"true" is true // false

"true" is "true" // true

"0" is false // false

"0" is 0 // false

0 is 0 // true

"" is false // false

난해한 JS 해결

12년 11월 29일 목요일

Page 16: CoffeeScript

cubes = (math.cube num for num in list)--------------------------------------------------cubes = (function() {

var _i, _len, _results;

_results = [];

for (_i = 0, _len = list.length; _i < _len; _i++) {

num = list[_i];

_results.push(math.cube(num));

}

return _results;

})();

간결한 코드

12년 11월 29일 목요일

Page 17: CoffeeScript

var _this = this;

$(this.config.add).click(function(e){

$(_this.config.todolist).append("<li>"+$(_this.config.todo).val()+"</li>");

});

--------------------------------------------------

$(@config.add).click (e)=>

$(@config.todolist).append "<li>#{$(@config.todo).val()}</li>"

가독성

12년 11월 29일 목요일

Page 18: CoffeeScript

ES.next

• Arrow Function

• Destructuring Assignment

• Default Value

12년 11월 29일 목요일

Page 19: CoffeeScript

12년 11월 29일 목요일

Page 20: CoffeeScript

단점

12년 11월 29일 목요일

Page 21: CoffeeScript

Not Superset of JavaScript.

12년 11월 29일 목요일

Page 22: CoffeeScript

Learning Curve

12년 11월 29일 목요일

Page 23: CoffeeScript

Debugging

12년 11월 29일 목요일

Page 24: CoffeeScript

실제로 써보니...

12년 11월 29일 목요일

Page 25: CoffeeScript

지나치게 엄격한 문법doSomething () -> 'hello'doSomething() -> 'hello'--------------------------------------------------doSomething(function() { return 'hello';});

doSomething()(function() { return 'hello';});

12년 11월 29일 목요일

Page 26: CoffeeScript

지나치게 엄격한 문법doSomething () -> 'hello'doSomething() -> 'hello'--------------------------------------------------doSomething(function() { return 'hello';});

doSomething()(function() { return 'hello';});

12년 11월 29일 목요일

Page 27: CoffeeScript

가독성은 케바케

if (five && six && seven) doStuff();

--------------------------------------------------

doStuff() if five and six and seven

12년 11월 29일 목요일

Page 28: CoffeeScript

SourceMap?

12년 11월 29일 목요일

Page 29: CoffeeScript

(Ruby || Python || Node.JS)+

CoffeeScript

12년 11월 29일 목요일

Page 30: CoffeeScript

Thank you.

12년 11월 29일 목요일