Questions tagged [coffeescript]

A language that transpiles to JavaScript. Use this tag for questions about programming with the CoffeeScript language.

From the CoffeeScript Homepage:

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

CoffeeScript can be used in any JavaScript environment. Included in a web page, it supports <script type="text/coffeescript"> tags; with node.js it can compile code on the command line, and it is also available as a Ruby gem.

The documentation and downloads can be found on the CoffeeScript website.

Common causes of unexpected behavior

  • Check your whitespace. Indentation is SIGNIFICANT. Mixing SPACE and TAB in indentation will create problems. Make sure you understand the rules for whitespace and make sure you triple-check this.

Popular questions

###Freely available CoffeeScript programming books

Video Tutorial

Codeschool CoffeeScript Tutorial - Awesome place to start with CoffeeScript.

9747 questions
63
votes
4 answers

Checkbox not binding to scope in angularjs

I am trying to bind a checkbox to scope using ng-model. The checkbox's initial state corresponds to the scope model just fine, but when I check/uncheck the checkbox, the model does not change. Some things to note is that the template is…
chris
  • 6,653
  • 6
  • 41
  • 54
61
votes
1 answer

Coffeescript unmatched outdent error

I'm getting the error SyntaxError: Unmatched OUTDENT on line 9 when I try to compile the following coffeescript code. I'm not sure what I'm doing wrong. the indentation seems to be right, and I have everything where I want it. row_possibilities =…
NielMalhotra
  • 1,375
  • 2
  • 13
  • 22
60
votes
2 answers

Switch case statement in coffee script

I have a few different buttons that are calling the same function and I would like to have them wrapped in a switch statement instead of using a bunch of else if conditions. Any help would be great!!! events: "click .red, .blue, #black, #yellow" :…
user992731
  • 3,400
  • 9
  • 53
  • 83
59
votes
8 answers

Clean way to remove element from javascript array (with jQuery, coffeescript)

There are many questions about this, not least: jQuery version of array contains, a solution with the splice method and many more. However, they all seem complicated and annoying. With the combined powers of javascript, jQuery and coffeescript,…
Peter
  • 127,331
  • 53
  • 180
  • 211
58
votes
2 answers

Does CoffeeScript allow JavaScript-style == equality semantics?

I love that CoffeeScript compiles == into the JavaScript === operator. But what if you want the original JS == semantics? Are they available? I've pored over the documentation and can't find anything enabling this. More generally, is there a way to…
Justin Morgan - On strike
  • 30,035
  • 12
  • 80
  • 104
56
votes
3 answers

Coffeescript 'this' inside jQuery .each()

I have some coffeescript like the following: class foo: @bar = 'bob loblaw' processRows: -> $("#my-table>tr").each -> id = $(this).attr("id") @processRow id processRow: (id) -> console.log @bar +…
user524276
55
votes
2 answers

NodeJS vs Play Framework for large project

I am really torn between two different stacks with which to build a large application. One the one hand there is this option: Node.js express coffee script coffeekup mongoose/mongodb or presistencejs/mysql Play Framework w/ Scala Anorm w/…
Jason Miesionczek
  • 14,268
  • 17
  • 76
  • 108
55
votes
4 answers

How to pass two anonymous functions as arguments in CoffeScript?

I want to pass two anonymous functions as arguments for jQuery's hover, like so: $('element').hover( function() { // do stuff on mouseover }, function() { // do stuff on mouseout } ); It's easy with just one – hover -> – but what is…
glortho
  • 13,120
  • 8
  • 49
  • 45
55
votes
4 answers

How to add a query to a webpack loader with multiple loaders?

I have this Babel loader that's working { test: /\.jsx?$/, loader: 'babel', query: babelSettings, exclude: /node_modules/ }, But now I want a CoffeeScript loader but I want to pipe it through Babel to get the the fancy HMR stuff { test:…
Chet
  • 18,421
  • 15
  • 69
  • 113
54
votes
5 answers

Were `do...while` loops left out of CoffeeScript...?

In CoffeeScript, the while loop comes standard: while x() y() However, the following1 doesn't work: do y() while x() And this is simply sugar for the first example: y() while x() Does CoffeeScript come with a built-in loop that executes at…
ClosureCowboy
  • 20,825
  • 13
  • 57
  • 71
54
votes
2 answers

require()'ing a CoffeeScript file from a JavaScript file or REPL

I'm using Node.js and wanting to incorporate CoffeeScript into my workflow. I have two use-cases: I want to be able to write JavaScript files which require() CoffeeScript modules I want to be able to load CoffeeScript modules from within the node…
nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101
53
votes
6 answers

Debugging CoffeeScript line-by-line

Is there a way to debug CoffeeScript line-by-line? I understand that it compiles into Javascript. But this sounds like it could make it a pain to debug.
Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
52
votes
3 answers

How to access instance variables in CoffeeScript engine inside a Slim template

I have a Rails controller in which I am setting a instance variable - @user_name = "Some Username" In my .slim template I am using coffee engine to generate javascript and want to print out the user name from client-sie javascript code - coffee: …
kapso
  • 11,703
  • 16
  • 58
  • 76
52
votes
3 answers

Default function parameter ordering

Reading through this, I came to the bit on default values for function arguments: fill = (container, liquid = "coffee") -> "Filling the #{container} with #{liquid}..." That's neat, but then I tried this: fill = (container="mug", liquid =…
nmichaels
  • 49,466
  • 12
  • 107
  • 135
52
votes
2 answers

I can't write multiline codes in Coffeescript Interactive Mode(REPL)

When I typed multiline in coffeescript interactive mode, an error occrured. For example, I want to try the following code: kids = brother: name: "Max" age: 11 sister: name: "Ida" age: 9 This Error was displayed: coffee> kids =…
utwang
  • 1,474
  • 11
  • 16