$(document).ready(function(){ jQuery.each($('a.auto_remote'), function(){ setInterval(function(remote_link) { $.ajax({ url: $(remote_link).attr('href') }); }, 10000, this); }); });In CoffeeScript it is tidy like this:
$(document).ready -> jQuery.each $("a.auto_remote"), -> setInterval ((remote_link) -> $.ajax url: $(remote_link).attr("href") ), 10000, thisThe first that attracts attention is the syntactic sugar like Ruby, Python or Haskell also offer. No semicolons, less brackets, just more readable. Furthermore you noticed the alias "->" for functions. Practical:
$(document).ready(function(){ // some codes });In CoffeeScript:
$(document).ready -> // some codes... sweet.
Read the CoffeeScript Tutorial and check how your JavaScript looks like converted into CoffeeScript.
Supported by CoffeeScript 1.4.0
Keine Kommentare:
Kommentar veröffentlichen