coffeescript

Documentation of Meteor's coffeescript package.

CoffeeScript is a little language thatcompiles into JavaScript. It provides a simple syntax without lots ofbraces and parentheses. The code compiles one-to-one into theequivalent JS, and there is no interpretation at runtime.

CoffeeScript is supported on both the client and the server. Filesending with .coffee, .litcoffee, or .coffee.md are automaticallycompiled to JavaScript.

Namespacing and CoffeeScript

Here’s how CoffeeScript works with Meteor’s namespacing.

  • Per the usual CoffeeScript convention, CoffeeScript variables arefile-scoped by default (visible only in the .coffee file wherethey are defined.)

  • When writing a package, CoffeeScript-defined variables can beexported like any other variable (see Package.js). Exporting a variable pulls it up topackage scope, meaning that it will be visible to all of the code inyour app or package (both .js and .coffee files).

  • Package-scope variables declared in .js files are visible in any.coffee files in the same app or project.

  • There is no way to make a package-scope variable from a .coffeefile other than exporting it. We couldn’t figure out a way to makethis fit naturally inside the CoffeeScript language. If you want touse package-scope variables with CoffeeScript, one way is to make ashort .js file that declares all of your package-scopevariables. They can then be used and assigned to from .coffeefiles.

  • If you want to share variables between .coffee files in the samepackage, and don’t want to separately declare them in a .js file,we have an experimental feature that you may like. An object calledshare is visible in CoffeeScript code and is shared across all.coffee files in the same package. So, you can write share.foofor a value that is shared between all CoffeeScript code in apackage, but doesn’t escape that package.

Heavy CoffeeScript users, please let us know how this arrangementworks for you, whether share is helpful for you, and anything elseyou’d like to see changed.

Modules and CoffeeScript

See Modules » Syntax » CoffeeScript.