3 ms·
JavaScript has always had a gorgeous object model hidden within Java-esque syntax. CoffeeScript is an attempt to expose the good parts of JavaScript through syn
by jashkenas 17y ago
JavaScript has always had a gorgeous object model hidden within Java-esque syntax. CoffeeScript is an attempt to expose the good parts of JavaScript through syntax that favors expressions over statements, cuts down on punctuation noise, and provides pretty function literals. This CoffeeScript:
square: x => x * x.
Compiles into this JavaScript:
var square = function(x) {
return x * x;
};
If anyone has specific ideas about aspects of JavaScript that they think could be more convenient or better-looking, I'd love to hear them. Cheers.
- messel 17y agoLooks great, I'll need time to dig in but Thank You in advance
- j_baker 17y agoAlright, this is bugging me. Why are you using colons for assignment?
- jrockway 17y agoI am not the author, but I assume because it's nice-looking, and JavaScript already uses it for assignment (inconsistently). Consider: var foo = 42; { foo: 42 } Why make the two concepts different? Also, it's "binding", not assignment.
- jashkenas 17y agoa: 1 b: 2 obj: { a: 1 b: 2 } Quite right, and internally, both kinds of assignment compile into a CoffeeScript AssignNode. The latter is just tagged as occurring within an object literal. Having the commas be optional in multiline objects also helps make both kinds of assignment look identical. (And I'm calling it assignment because saying "binding" in JavaScript usually means that you're binding a function to a "this" context object)
- nir 17y agoAny chance you'll allow equal sign as well as colon? For all of us coders conditioned by years of programming to automatically use "="... Looks beautiful, in any case.
- j_baker 17y agoErm... no, it's assignment. At least according to the documentation: http://jashkenas.github.com/coffee-script/#assignment http://jashkenas.github.com/coffee-script/#assignment At any rate, I was just curious. To me, x = 1 looks more intuitive than: x: 1 But that's just my personal preference.