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
50
votes
7 answers

Can I run coffeescript in Heroku?

I have a node.js app written in CoffeeScript. I'm wondering what is needed in order to host the app on Heroku. Thanks
donald
  • 23,587
  • 42
  • 142
  • 223
50
votes
2 answers

coffeescript multiline strings compile into multiline strings

How come that this string "answer to life the universe and everything is #{40+2} " compiles into " answer to life the universe and everything is " + (40 + 2) + ""; how can I force coffescript to keep it multiline (keeping string…
iLemming
  • 34,477
  • 60
  • 195
  • 309
50
votes
4 answers

Why would a developer ever need PhantomJS as opposed to just using some testing framework?

I'm not sure why PhantomJS is necessary and I'm hoping someone can help.
Leila Hamon
  • 2,505
  • 7
  • 24
  • 32
49
votes
4 answers

How do I define methods in a Mongoose model?

My locationsModel file: mongoose = require 'mongoose' threeTaps = require '../modules/threeTaps' Schema = mongoose.Schema ObjectId = Schema.ObjectId LocationSchema = latitude: String longitude: String locationText: String Location = new…
Shamoon
  • 491
  • 1
  • 4
  • 3
49
votes
18 answers

How can I compile CoffeeScript from .NET?

I want to write an HttpHandler that compiles CoffeeScript code on-the-fly and sends the resulting JavaScript code. I have tried MS [JScript][1] and IronJS without success. I don't want to use [Rhino][2] because the Java dependency would make it too…
liammclennan
  • 5,295
  • 3
  • 34
  • 30
49
votes
11 answers

Exclude route from express middleware

I have a node app sitting like a firewall/dispatcher in front of other micro services and it uses a middleware chain like below: ... app.use app_lookup app.use timestamp_validator app.use request_body app.use checksum_validator app.use…
kreek
  • 8,774
  • 8
  • 44
  • 69
48
votes
8 answers

Remove a value from an array in CoffeeScript

I have an array: array = [..., "Hello", "World", "Again", ...] How could I check if "World" is in the array? Then remove it if it exists? And have a reference to "World"? Sometimes maybe I wanna match a word with a regexp and in that case I won't…
ajsie
  • 77,632
  • 106
  • 276
  • 381
48
votes
6 answers

Functions In CoffeeScript

I'm trying to convert a function from Javascript to CoffeeScript. This is the code: function convert(num1, num2, num3) { return num1 + num2 * num3; } But how I can do that in CoffeeScript? I'm trying to run the function from an HTML source…
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
48
votes
11 answers

what's the least resistance path to debugging mocha tests?

Edit Nov 2016: Node now has a built in debugger that you can start with --inspect. This answer explains it: https://stackoverflow.com/a/39901169/30946. I'm building a mocha test in coffeescript. Right at the top of the test I have: require…
jcollum
  • 43,623
  • 55
  • 191
  • 321
47
votes
7 answers

My JavaScript patterns/practices stink. Where should I seek help?

I've been working almost exclusively on back-end tasks for the past few years, and I've just noticed that most JavaScript (and CoffeeScript) projects have got a helluva lot prettier in my absence. I work primarily in a rails environment, and almost…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
47
votes
5 answers

How to document CoffeeScript source code with JSDoc?

I have some code written in CoffeeScript and I want to optimize the generated JavaScript with the Google Closure Compiler, so these files need to be documented with JSDoc. My question is, how can I document the *.coffee files to generate javascript…
aztack
  • 4,376
  • 5
  • 32
  • 50
46
votes
6 answers

Coffeescript ||= analogue?

I'm primarily a Rails developer, and so in whipping up a little script for my company's Hubot instance, I was hoping to accomplish the following: robot.brain.data.contacts ||= {} Or, only make this new hash if it doesn't already exist. The idea…
Nick Coelius
  • 4,668
  • 3
  • 24
  • 30
46
votes
4 answers

How to return object explicitly in CoffeeScript

This works: myfunc = () -> id: 3 name: 'myname' But I want to be explicit about returning object. myfunc = () -> return id: 3 name: 'myname' But I get "Unexpected 'INDENT'" error. What's wrong with the above code?
Alice
  • 909
  • 1
  • 11
  • 15
45
votes
7 answers

Compile CoffeeScript on Save?

Is there anyway to easily compile CoffeeScript on save? I'm using TextMate or Sublime Text 2.
fancy
  • 48,619
  • 62
  • 153
  • 231
45
votes
3 answers

How to see what states are configured in AngularJS / UI-Router?

Is there a way to see all of the states that have been set on $stateProvider? In this case, I would like my state assignments to be distributed across many files. I would like to inspect the built states on run or config in a different file. For…
SimplGy
  • 20,079
  • 15
  • 107
  • 144