CoffeeScript in 5mins
              @mackato - 2011.09.14 #izakaya.js




11   9   15
“CoffeeScript is a little language
               that compiles into JavaScript.”

11   9   15
Pros


               less code
              compile-time code check

              compiles into pure JavaScript



11   9   15
Cons

              require compile process

              little strange syntax

              debugging is too hard,
              yet.

11   9   15
Use Case
              Rails 3.1




11   9   15
Use Case
              Any other JavaScript Frameworks




11   9   15
JS to CoffeeScript
              $(document).ready(function() {
                init();
                some();
                $("a.link").click(function() {
                  $(this).fadeOut("slow", function () {
                    $(this).remove();
                  });
                });
              });




11   9   15
JS to CoffeeScript
              $(document).ready(function() {
                 init()
                 some()
                 $("a.link").click(function() {
                   $(this).fadeOut("slow", function () {
                      $(this).remove()
                    })
                 })
              })




11   9   15
JS to CoffeeScript
              $(document).ready function()
                init()
                some()
                $("a.link").click function()
                  $(this).fadeOut "slow", function ()
                    $(this).remove()




11   9   15
JS to CoffeeScript
              $(document).ready ->
                init()
                some()
                $("a.link").click ->
                  $(this).fadeOut "slow", ->
                    $(this).remove()




11   9   15
JavaScript build is necessary
                       without CoffeeScript

                  concatenate
              <script src="/javascripts/jquery.js"></script>
              <script src="/javascripts/jquery.min.js"></script>
              <script src="/javascripts/application.js"></script>




              <script src="/javascripts/all.js"></script>




11   9   15
JavaScript build is necessary
                          without CoffeeScript

                    minify
                      (function( window, undefined ) {
                        var document = window.document,
                            navigator = window.navigator,
                            location = window.location;




              (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?
              a.defaultView||a.parentWindow:!1}function cv(a){if(!cj[a]){var b=f("
              +">").appendTo("body"),d=b.css("display");b.remove();if(d==="none"||
              d===""){ck||
              (ck=c.createElement("iframe"),ck.frameBorder=ck.width=ck.height=0),c
11   9   15   .appen
JavaScript build is necessary
                       without CoffeeScript

                    concatenate        minify
              js



              js                  js            js



              js



11   9   15
JavaScript build is necessary
                           without CoffeeScript

                        compile concatenate minify
              coffee         js



              coffee         js          js        js



              coffee         js



11   9   15
Cons

              require compile process # not cons

              little strange syntax

              debugging is too hard,
              yet.

11   9   15

CoffeeScript in 5mins

  • 1.
    CoffeeScript in 5mins @mackato - 2011.09.14 #izakaya.js 11 9 15
  • 2.
    “CoffeeScript is alittle language that compiles into JavaScript.” 11 9 15
  • 3.
    Pros less code compile-time code check compiles into pure JavaScript 11 9 15
  • 4.
    Cons require compile process little strange syntax debugging is too hard, yet. 11 9 15
  • 5.
    Use Case Rails 3.1 11 9 15
  • 6.
    Use Case Any other JavaScript Frameworks 11 9 15
  • 7.
    JS to CoffeeScript $(document).ready(function() { init(); some(); $("a.link").click(function() { $(this).fadeOut("slow", function () { $(this).remove(); }); }); }); 11 9 15
  • 8.
    JS to CoffeeScript $(document).ready(function() { init() some() $("a.link").click(function() { $(this).fadeOut("slow", function () { $(this).remove() }) }) }) 11 9 15
  • 9.
    JS to CoffeeScript $(document).ready function() init() some() $("a.link").click function() $(this).fadeOut "slow", function () $(this).remove() 11 9 15
  • 10.
    JS to CoffeeScript $(document).ready -> init() some() $("a.link").click -> $(this).fadeOut "slow", -> $(this).remove() 11 9 15
  • 11.
    JavaScript build isnecessary without CoffeeScript concatenate <script src="/javascripts/jquery.js"></script> <script src="/javascripts/jquery.min.js"></script> <script src="/javascripts/application.js"></script> <script src="/javascripts/all.js"></script> 11 9 15
  • 12.
    JavaScript build isnecessary without CoffeeScript minify (function( window, undefined ) { var document = window.document, navigator = window.navigator, location = window.location; (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9? a.defaultView||a.parentWindow:!1}function cv(a){if(!cj[a]){var b=f(" +">").appendTo("body"),d=b.css("display");b.remove();if(d==="none"|| d===""){ck|| (ck=c.createElement("iframe"),ck.frameBorder=ck.width=ck.height=0),c 11 9 15 .appen
  • 13.
    JavaScript build isnecessary without CoffeeScript concatenate minify js js js js js 11 9 15
  • 14.
    JavaScript build isnecessary without CoffeeScript compile concatenate minify coffee js coffee js js js coffee js 11 9 15
  • 15.
    Cons require compile process # not cons little strange syntax debugging is too hard, yet. 11 9 15