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
130
votes
10 answers

React input defaultValue doesn't update with state

I'm trying to create a simple form with react, but facing difficulty having the data properly bind to the defaultValue of the form. The behavior I'm looking for is this: When I open my page, the Text input field should be filled in with the text of…
117
votes
5 answers

Is there any way to not return something using CoffeeScript?

It seems like CoffeeScript automatically returns the last item in a scope. Can I avoid this functionality?
Shamoon
  • 41,293
  • 91
  • 306
  • 570
115
votes
13 answers

CoffeeScript on Windows?

How can I try CoffeeScript on Windows? The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation EDIT: Since I asked this a while ago, many new answers have appeared. The number ( and quality ) of…
Nick Perkins
  • 8,034
  • 7
  • 40
  • 40
114
votes
4 answers

What does "Splats" mean in the CoffeeScript tutorial?

Looking at this CoffeeScript tutorial : http://jashkenas.github.com/coffee-script/ I don't quite see what the Splats is for. What is this construction? Where does it come from (historically)
interstar
  • 26,048
  • 36
  • 112
  • 180
114
votes
15 answers

React onClick and preventDefault() link refresh/redirect?

I'm rendering a link with react: render: -> `upvote` Then, above I have the upvote function: upvote: -> // do stuff (ajax) Before link I had span in that place but I need to switch to link and…
Wordpressor
  • 7,173
  • 23
  • 69
  • 108
111
votes
3 answers

Simplest way to check if key exists in object using CoffeeScript

In CoffeeScript, what is the simplest way to check if a key exists in an object?
ajsie
  • 77,632
  • 106
  • 276
  • 381
107
votes
9 answers

Defining an array of anonymous objects in CoffeeScript

How do I define an array of anonymous objects in CoffeeScript? Is this possible at all, using the YAML syntax? I know that having an array of named objects is quite easy: items:[ item1: name1:value1 item2: name:value2 ] However,…
Preslav Rachev
  • 3,983
  • 6
  • 39
  • 63
100
votes
3 answers

In CoffeeScript how do you append a value to an Array?

What is the prescribed way to append a value to an Array in CoffeeScript? I've checked the PragProg CoffeeScript book but it only discusses creating, slicing and splicing, and iterating, but not appending.
Dave Sag
  • 13,266
  • 14
  • 86
  • 134
96
votes
16 answers

How can I manage client-side JavaScript dependencies?

Although there are great solutions to manage dependencies on the server side, I could not find any that satisfies all my needs to have a coherent client side JavaScript dependency management workflow. I want to satisfy these five…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
93
votes
7 answers

Has anyone used Coffeescript for a production application?

Coffeescript looks pretty cool. Has anyone used it? What are its Pros & Cons?
Esteban Araya
  • 29,284
  • 24
  • 107
  • 141
90
votes
11 answers

Easiest way to check if string is null or empty

I've got this code that checks for the empty or null string. It's working in testing. eitherStringEmpty= (email, password) -> emailEmpty = not email? or email is '' passwordEmpty = not password? or password is '' eitherEmpty = emailEmpty ||…
jcollum
  • 43,623
  • 55
  • 191
  • 321
89
votes
8 answers

CoffeeScript Undefined

In javascript to check if a variable was never created, we just do if (typeof MyVariable !== "undefined"){ ... } I was wonder how I do that in coffeescript?... I try something like if (MyVariable?false){ ... } but this check if MyVariable is a…
Jaider
  • 14,268
  • 5
  • 75
  • 82
88
votes
11 answers

Environment detection: node.js or browser

I'm developping a JS-app that needs to work both on the client side and the server side (in Javascript on a browser and in Node.js), and I would like to be able to reuse the parts of the code that are used for both sides. I have found out that…
edi9999
  • 19,701
  • 13
  • 88
  • 127
87
votes
8 answers

Coffeescript --- How to create a self-initiating anonymous function?

How to write this in coffeescript? f = (function(){ // something })(); Thanks for any tips :)
user537339
  • 1,851
  • 2
  • 15
  • 19
87
votes
8 answers

How do I get the Back Button to work with an AngularJS ui-router state machine?

I have implemented an angularjs single page application using ui-router. Originally I identified each state using a distinct url however this made for unfriendly, GUID packed urls. So I have now defined my site as a much simpler state-machine. The…
biofractal
  • 18,963
  • 12
  • 70
  • 116