CoffeeScript
        What’s good?




        2010.10.10
     OutsideratFRENDS
“        CoffeeScriptisBeautiful
                          
INeverWanttoWritePlain


                                                     ”
            JavaScriptAgain


                          SamStephenson
                        (prototype.jscreator)
좋은것과
익숙하지
않은것을
구별하기가
쉽지않다.
Comparing
JavaScriptCoffeeScript
FunctionSyntax
$(a).click(function(event){
$(this).addClass(busy);
})
$(a).click(function(event){
$(this).addClassbusy
})
$(a).click(function(event){
$(@).addClassbusy
})
$(a).click(event)-
$(@).addClassbusy
LoopSyntax
vardata=[];
for(vari=0;i84;i++){
data.push(i*10/84);
}
data=[]
foriin[0..83]
data.push(i*10/84)
data=[]
data=i*10/84foriin[0..83]
data=i*10/84foriin[0..83]
List
Comprehensions
init_board:function(){
this.board=newArray(WIDTH);
for(varx=0;xthis.board.length;x++){
this.board[x]=newArray(HEIGHT)
for(vary=0;ythis.board[x].length;y++){
this.board[x][y]=false;
}
}
}
init_board:-
this.board=newArray(WIDTH)
forxinthis.board
this.board[x]=newArray(HEIGHT)
foryinthis.board[x]
this.board[x][y]=false
init_board:-
@board=forxin[0...WIDTH]

this.board[x]=newArray(HEIGHT)
foryinthis.board[x]
this.board[x][y]=false
init_board:-
@board=forxin[0...WIDTH]


foryin[0...HEIGHT]
false
init_board:-
@board=
(falseforyin[0...HEIGHT]forxin[0...WIDTH])
SettingFields
constructor:function(keys,tokens){
this.keys=keys;
this.tokens=tokens;
}
constructor:(keys,tokens)-
this.keys=keys
this.tokens=tokens
constructor:(keys,tokens)-
@keys=keys
@tokens=tokens
constructor:(@keys,@tokens)-
Defensive
Programming
varcountry=null;
if(typeofmodel!=='undefined'
model
typeofmodel.profile==='function'){

varprofile=model.profile();

if(profile
profile.location
profile.location.country){
country=profile.location.country.toString();
}
}
country=null
iftypeofmodelisnt'undefined'
model
typeofmodel.profileis'function'

profile=model.profile()

ifprofile
profile.location
profile.location.country
country=profile.location.country.toString()
country=null
iftypeofmodelisnt'undefined'
model
typeofmodel.profileis'function'

profile=model.profile()

ifprofile
profile.location

country=profile.location.country?.toString()
country=null
iftypeofmodelisnt'undefined'
model
typeofmodel.profileis'function'

profile=model.profile()

ifprofile


country=profile.location?.country?.toString()
country=null
iftypeofmodelisnt'undefined'
model
typeofmodel.profileis'function'

profile=model.profile()




country=profile?.location?.country?.toString()
country=null
iftypeofmodelisnt'undefined'
model


profile=model.profile?()?




country=profile?.location?.country?.toString()
country=null




profile=model?.profile?()?




country=profile?.location?.country?.toString()
profile=model?.profile?()?




country=profile?.location?.country?.toString()
profile=model?.profile?()?




country=profile
?.location?.country?.toString()
country=model?.profile?()
?.location?.country?.toString()
BareObjects
$.ajax({
url:path,
timeout:5,
data:{from:workspace},

dataType:html,
success:function(data){
return$(#result).html(data);
}
});
$.ajax({
url:path,
timeout:5,
data:{from:workspace},

dataType:html,
success:(data)-
return$(#result).html(data)

})
$.ajax{
url:path
timeout:5
data:{from:workspace}

dataType:html
success:(data)-
$(#result).htmldata

}
$.ajax
url:path
timeout:5
data:
from:workspace
dataType:html
success:(data)-
$(#result).htmldata
FunctionBinding
functionrequest(){
$.get(this.person.url,
(function(data){
$(this.el).html(data);
}).bind(this)
)
}
request=()-
$.get(this.person.url,
((data)-
$(this.el).html(data);
).bind(this)
)
request=()-
$.get(this.person.url,
((data)-
$(@el).htmldata
).bind(@)
)
request=()-
$.get(this.person.url,
(data)=
$(@el).htmldata

)
request=()-
$.getthis.person.url,
(data)=
$(@el).htmldata
BadThings
Compile
      is
inconvenience
Debugging
    is
hard
But
It’sComing
ShortSourceMap
          Demo
http://www.youtube.com/watch?v=UAGAB-yT0lQ
ToolsforCoffeeScript
js2coffee
convertJavaScripttoCoffeeScript


http://js2coffee.org/
CoffeeTable
BookmarkletforCoffeeScriptConsole


http://code.alecperkins.net/coffeetable/
cake
SimpleBuildSystemlikeMake

https://github.com/jashkenas/coffee-script/wiki/[HowTo]-Compiling-and-Setting-Up-Build-Tools
CoffeeKup
MarkupasCoffeeScript


http://coffeekup.org/
Thankyou.



                    @Outsideris
         outsideris@gmail.com
      http://blog.outsider.ne.kr
Resources
http://www.flickr.com/photos/41754875@N00/5942994577

http://www.flickr.com/photos/61172365@N00/481680379

Coffeescript - what's good