-
Notifications
You must be signed in to change notification settings - Fork 0
CoffeeScript
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.
- No semicolon insertion wars, as CoffeeScript doesn't use semicolons to end statements.
- No bugs because of forgotten local
var
declarations, as CoffeeScript declares all variables automatically. - No global variables.
- No bugs caused by Javascript
==
as CoffeeScript==
is compiled to Javascript===
. - Cleaner callback chains as the function keyword and argument list parentheses aren't needed.
- Special function declaration
=>
that keepsthis
defined in callbacks. - Proper
for x in list
loops without Javascript'sisOwnProperty
. - A syntax for declaring classes.
- Additional niceties such as list comprehensions.
- CoffeeScript needs to be translated to Javascript before running.
- Debuggers show different line numbers (unless source maps are in use).
- The tutorial homepage doesn't specify or even mention all language features.
- Gotcha: All functions return the value of their last line even if the author didn't mean to.
- Gotcha: rules for splitting function call arguments based on optional parentheses, optional commas and line breaks are weird.
- Gotcha: Whitespace in
a +b
causes interpretationa(+b)
. - Gotcha: The condition
if not key in object
is parsed asif (not key) in object
- 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) ->