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
958
votes
5 answers

How does Trello access the user's clipboard?

When you hover over a card in Trello and press Ctrl+C, the URL of this card is copied to the clipboard. How do they do this? As far as I can tell, there is no Flash movie involved. I've got Flashblock installed, and the Firefox network tab shows no…
Boldewyn
  • 81,211
  • 44
  • 156
  • 212
761
votes
36 answers

Why doesn't adding CORS headers to an OPTIONS route allow browsers to access my API?

I am trying to support CORS in my Node.js application that uses the Express.js web framework. I have read a Google group discussion about how to handle this, and read a few articles about how CORS works. First, I did this (code is written in…
mikong
  • 8,270
  • 3
  • 16
  • 15
719
votes
25 answers

How to use executables from a package installed locally in node_modules?

How do I use a local version of a module in node.js. For example, in my app, I installed coffee-script: npm install coffee-script This installs it in ./node_modules and the coffee command is in ./node_modules/.bin/coffee. Is there a way to run this…
typeoneerror
  • 55,990
  • 32
  • 132
  • 223
410
votes
15 answers

How to run Gulp tasks sequentially one after the other

in the snippet like this: gulp.task "coffee", -> gulp.src("src/server/**/*.coffee") .pipe(coffee {bare: true}).on("error",gutil.log) .pipe(gulp.dest "bin") gulp.task "clean",-> gulp.src("bin", {read:false}) .pipe…
iLemming
  • 34,477
  • 60
  • 195
  • 309
332
votes
8 answers

Ternary operation in CoffeeScript

I need to set value to a that depends on a condition. What is the shortest way to do this with CoffeeScript? E.g. this is how I'd do it in JavaScript: a = true ? 5 : 10 # => a = 5 a = false ? 5 : 10 # => a = 10
evfwcqcg
  • 15,755
  • 15
  • 55
  • 72
319
votes
9 answers

How do I define global variables in CoffeeScript?

On Coffeescript.org: bawbag = (x, y) -> z = (x * y) bawbag(5, 10) would compile to: var bawbag; bawbag = function(x, y) { var z; return (z = (x * y)); }; bawbag(5, 10); compiling via coffee-script under node.js wraps that so: (function()…
handloomweaver
  • 4,971
  • 7
  • 29
  • 33
254
votes
10 answers

Exec : display stdout "live"

I have this simple script : var exec = require('child_process').exec; exec('coffee -cw my_file.coffee', function(error, stdout, stderr) { console.log(stdout); }); where I simply execute a command to compile a coffee-script file. But stdout…
mravey
  • 4,380
  • 2
  • 21
  • 31
233
votes
11 answers

Null-safe property access (and conditional assignment) in ES6/2015

Is there a null-safe property access (null propagation / existence) operator in ES6 (ES2015/JavaScript.next/Harmony) like ?. in CoffeeScript for example? Or is it planned for ES7? var aThing = getSomething() ... aThing = possiblyNull?.thing This…
P Varga
  • 19,174
  • 12
  • 70
  • 108
209
votes
6 answers

how to write setTimeout with params by Coffeescript

Please tell me how to write javascript below in coffeescript. setTimeout(function(){ something(param); }, 1000);
tomodian
  • 6,043
  • 4
  • 25
  • 29
192
votes
4 answers

How to iterate over the keys and values in an object in CoffeeScript?

I have an object (an "associate array" so to say - also known as a plain JavaScript object): obj = {} obj["Foo"] = "Bar" obj["bar"] = "Foo" I want to iterate over obj using CoffeeScript as follows: # CS for elem in obj bu the CS code above…
jhchen
  • 14,355
  • 14
  • 63
  • 91
191
votes
8 answers

Can I use CoffeeScript instead of JS for node.js?

What are my restrictions if I want to code node.js and use CoffeeScript? Can I do anything I'd be able to do in JS?
donald
  • 23,587
  • 42
  • 142
  • 223
150
votes
5 answers

How do I comment in CoffeeScript? "/* this */" doesn't work

In what ways can you comment in CoffeeScript? The documentation say you can use three hash symbols to start and close a comment block: ### Comments go here ### I've found that I can sometimes use the following two formats `// backticks allow…
Eric Hu
  • 18,048
  • 9
  • 51
  • 67
145
votes
22 answers

Can I determine if a string is a MongoDB ObjectID?

I am doing MongoDB lookups by converting a string to BSON. Is there a way for me to determine if the string I have is a valid ObjectID for Mongo before doing the conversion? Here is the coffeescript for my current findByID function. It works great,…
Will
  • 2,082
  • 2
  • 16
  • 13
143
votes
5 answers

Uploading base64 encoded Image to Amazon S3 via Node.js

Yesterday I did a deep night coding session and created a small node.js/JS (well actually CoffeeScript, but CoffeeScript is just JavaScript so lets say JS) app. what's the goal: client sends a canvas datauri (png) to server (via socket.io) server…
Franz Enzenhofer
  • 3,666
  • 5
  • 19
  • 30
142
votes
4 answers

CoffeeScript, When to use fat arrow (=>) over arrow (->) and vice versa

When building a class in CoffeeScript, should all the instance method be defined using the => ("fat arrow") operator and all the static methods being defined using the -> operator?
Ali Salehi
  • 6,899
  • 11
  • 49
  • 75
1
2 3
99 100