Skip to content
haphut edited this page Feb 3, 2014 · 2 revisions

We have written the Navigator prototype in CoffeeScript, which is a language that is very similar to Javascript but has cleaner syntax (resembling Python).

The highly recommended slides from Aseem Kishore's talk in June 2013 present the main features of CoffeeScript but also explain a few powerful idioms and tricks.

Advantages

  1. No semicolon insertion wars, as CoffeeScript doesn't use semicolons to end statements.
  2. No bugs because of forgotten local var declarations, as CoffeeScript declares all variables automatically.
  3. No global variables.
  4. No bugs caused by Javascript == as CoffeeScript == is compiled to Javascript ===.
  5. Cleaner callback chains as the function keyword and argument list parentheses aren't needed.
  6. Special function declaration => that keeps this defined in callbacks.
  7. Proper for x in list loops without Javascript's isOwnProperty.
  8. A syntax for declaring classes.
  9. Additional niceties such as list comprehensions.

Disadvantages

  1. CoffeeScript needs to be translated to Javascript before running.
  2. Debuggers show different line numbers (unless source maps are in use).
  3. The tutorial homepage doesn't specify or even mention all language features.
  4. Gotcha: All functions return the value of their last line even if the author didn't mean to.
  5. Gotcha: rules for splitting function call arguments based on optional parentheses, optional commas and line breaks are weird.
  6. Gotcha: Whitespace in a +b causes interpretation a(+b).
  7. Gotcha: The condition if not key in object is parsed as if (not key) in object
  8. Gotcha: Undocumented feature of referencing a predefined constructor leads to no error if constructor is not a function, e.g. constructor: (@config) vs. constructor: (@config) ->