5. no brace, semicolon
if(true){ if true
alert(1); alert 1
}else{ else
alert(2); alert 2
}
12년 11월 29일 목요일
6. Function
var square = function(x){ square = (x) -> x * x
return x * x;
}
12년 11월 29일 목요일
7. Object
var bareObj = { bareObj =
“name” : “전용우”, name : “전용우”
“id” : “mixed” id : “mixed”
};
12년 11월 29일 목요일
8. Conditional Assignment
var date;
if(friday){
date = sue;
}else{
date = jill;
}
---------------------------------------------------
date = if friday then sue else jill
12년 11월 29일 목요일
9. Loops/comprehensions
foods = ['broccoli', 'spinach', 'chocolate']
eat food for food in foods when food isnt 'chocolate'
12년 11월 29일 목요일
10. 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"); # A
console.log joinArgs("a", "b"); #AB
console.log joinArgs("a", "B", "C", "d"); #AbcD
12년 11월 29일 목요일
11. String Interpolation
square = (x) -> x*x
id = "mixed"
str = "#{id} is #{square()}"
12년 11월 29일 목요일
12. Destructuring
Assignment
theBait = 1000
theSwitch = 0
[theBait, theSwitch] = [theSwitch, theBait]
12년 11월 29일 목요일
13. Function binding
Account = (customer, cart) ->
@customer = customer
@cart = cart
$('.shopping_cart').bind 'click', (event) =>
@customer.purchase @cart
12년 11월 29일 목요일
15. 난해한 JS 해결
"true" == true // true "true" is true // false
"true" === true // false "true" is "true" // true
"0" == false // true "0" is false // false
"0" == 0 // true "0" is 0 // false
0 === false // false 0 is 0 // true
"" == false // true "" is false // false
12년 11월 29일 목요일
16. 간결한 코드
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일 목요일
17. 가독성
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일 목요일
18. ES.next
• Arrow Function
• Destructuring Assignment
• Default Value
12년 11월 29일 목요일