4 ms·
[Obviously I'm biased because I have a book to sell, but...] I'd call the gains "small but significant" in that case. The corresponding JS would be $.post
by TrevorBurnham 15y ago
[Obviously I'm biased because I have a book to sell, but...]
I'd call the gains "small but significant" in that case. The corresponding JS would be
$.post("/posts/update_title", {
new_title: input.val(),
id: something
}, function() {
return alert('done');
}, 'json');
What I really dislike about this is the use of curly braces to denote two completely different things: an object literal, and a function. Functions are extraordinarily privileged entities in JavaScript; they're the only way of creating scope, and they also change the context (`this`). Object are just a bunch of key-value pairs.
So to me, JavaScript's semantics are much clearer through the lens of CoffeeScript semantics: Curly braces are only used for object literals, and functions are denoted by a distinct symbol followed by indentation, except in one-liners like the above.
The extra compilation can be annoying (through largely transparent thanks to tools like Barista and the upcoming Rails 3.1 integration), but for me, it's always felt worth it. Debugging is harder, true, but I write code with fewer bugs in the first place. On net, learning CoffeeScript has been both a pleasure and a productivity boost.