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
45
votes
9 answers

Coffeescript: how do I convert a string to a number?

I am building a JSON object that is sent in a POST request. This object has properties that need to be converted from string type to integer type before sending. How does one do that with coffeescript?
nachonachoman
  • 802
  • 1
  • 13
  • 29
44
votes
6 answers

Cannot run Mocha with CoffeeScript

Makefile - Content: REPORTER = dot all: build build: @./node_modules/coffee-script/bin/coffee \ -c \ -o lib src clean: rm -rf lib mkdir lib watch: @./node_modules/coffee-script/bin/coffee \ -o lib \ …
Sameet
  • 2,191
  • 7
  • 28
  • 55
44
votes
7 answers

Sublime Text CoffeeScript build system: `env: node: No such file or directory`

I'm trying to set up a CoffeeScript build system in Sublime Text 3, but I keep getting the following error: env: node: No such file or directory [Finished in 0.0s with exit code 127] [cmd: ['coffee',…
CourtDemone
  • 5,772
  • 6
  • 23
  • 25
43
votes
8 answers

Object from comprehension in CoffeeScript [dict/hash comprehensions]

is there a way to return an object from a comprehension in coffeescript? something so that i could express this: form_values = () -> ret = {} ret[f.name] = f.value for f in $('input, textarea, select') return ret like this: form_values = ()…
aaronstacy
  • 6,189
  • 13
  • 59
  • 72
43
votes
6 answers

in CoffeeScript, how can I use a variable as a key in a hash?

eg: So: foo = "asdf" {foo: "bar"} eval foo # how do I get {"asdf": "bar"} ? # this will throw parse error: {(eval foo): "bar"} This is a simple syntax question: how do I get CoffeeScript to construct a hash dynamically, rather than doing it by…
Giles Bowkett
  • 529
  • 1
  • 4
  • 6
43
votes
4 answers

Determining whether one array contains the contents of another array in JavaScript/CoffeeScript

In JavaScript, how do I test that one array has the elements of another array? arr1 = [1, 2, 3, 4, 5] [8, 1, 10, 2, 3, 4, 5, 9].function_name(arr1) # => true
Zeck
  • 6,433
  • 21
  • 71
  • 111
43
votes
6 answers

CoffeeScript: Getter/Setter in Object Initializers

ECMAScript allows us to define getters or setters as following: [text/javascript] var object = { property: 7, get getable() { return this.property + 1; }, set setable(x) { this.property = x / 2; } }; I can work around if I'm using a…
fridojet
  • 1,276
  • 3
  • 15
  • 29
42
votes
5 answers

Equivalent Ruby .times in Coffeescript

What is the most concise equivalent Coffeescript to the following: # ruby 3.times { puts 'hi' } ? The best I could think of is: # coffeescript for n in [1..3] console.log 'hi'
sivabudh
  • 31,807
  • 63
  • 162
  • 228
42
votes
1 answer

Why does console.log(buffer) give me a hexadecimal list?

Here is my CoffeeScript: buffer = new Buffer 100 buffer[i] = i for i in [0..99] console.log buffer which compiles to var buffer, i; buffer = new Buffer(100); for (i = 0; i < buffer.length; i++) { buffer[i] = i; } …
Shamoon
  • 41,293
  • 91
  • 306
  • 570
42
votes
4 answers

Grunt: Watch multiple files, Compile only Changed

I'm new to Grunt, and so far I'm enjoying it very much. I want Grunt to compile only the changed files when running grunt watch In my Grunfile.coffee I currently have (relevant parts). Note: assets/javascript/app.coffee and assets/javascript/app.js…
pyronaur
  • 3,515
  • 6
  • 35
  • 52
42
votes
3 answers

Does the '@' symbol have special meaning in Javascript, Coffeescript or Jquery?

I have some code that looks like self = @ and then later on it's using @someMethodName or self.someMethodName Does @ have some special meaning?
Noah Clark
  • 8,101
  • 14
  • 74
  • 116
42
votes
9 answers

How to rotate a 3D object on axis three.js?

I have a great problem about the rotation in three.js I want to rotate my 3D cube in one of my game. //init geometry = new THREE.CubeGeometry grid, grid, grid material = new THREE.MeshLambertMaterial {color:0xFFFFFF * Math.random(),…
Tony Han
  • 2,130
  • 3
  • 24
  • 37
41
votes
6 answers

Rails: access controller instance variable in CoffeeScript or JavaScript asset file

In Rails 3.1 it is not possible to access controller instance variables in an asset js.erb or coffee.erb file using syntax such as <%= @foo %>, where @foo is set in the controller. So then the question is what are the best ways for passing…
Safa Alai
  • 1,223
  • 1
  • 15
  • 27
41
votes
3 answers

CoffeeScript - Referencing DOM nodes in Angular expressions is disallowed

My main question is simple : I get errors when doing DOM manipulation within Controllers or Directives however, the functionality works perfectly. Error: [$parse:isecdom] Referencing DOM nodes in Angular expressions is disallowed! Expression:…
Cosmin
  • 2,082
  • 3
  • 20
  • 24
40
votes
5 answers

How can I completely disable CoffeeScript in a Rails 3.1 app?

At the moment when I generate a new controller, Rails also generates a .js.coffee file for the controller as well. As I don't use CoffeeScript I want Rails instead generate .js files for me. Is it enough to comment out the coffee-rails gem to…
K Everest
  • 1,565
  • 5
  • 15
  • 23