Marcin Szczepanski, webqem
CFCamp 2013
“A better way of writing JavaScript”
Like TypeScript
Not like ClojureScript, Roy, etc
I'll get to that...
$(function () {
$(".link").click(function () {
console.log("You clicked a link: " + this.href);
});
});
$(function () {
$(".link").click(function () {
console.log("You clicked a link: " + this.href);
});
});
would be written as..
$ ->
$(".link").click ->
console.log "You clicked a link: #{@href}"
iffy: Immediately-Invoked Function Expression (IIFE)
console.log "x is NOT 2" if x != 2
NOT good practice!
result = (expression for object in array)
result = (expression for object in array when condition)
result = (expression for key of object)
result = (expression for own key, value of object)
Syntax stuff that didn't fit in the other categories!
npm install -g coffee-script
coffee # REPL
coffee file.coffee # run script
coffee -c file.coffee # compile
coffee -wc file.coffee # watch & compile
coffee -cm file.coffee # sourcemap
coffee -wmc *.coffee # ALL THE THINGS!
<script type="text/coffeescript">window.alert "Hello World!"</script>
var compiled = CoffeeScript.compile(source);