Naming Rules
In general write file_names_like_this.cjsx
, function_names_like_this
, variable_names_like_this
, ClassNamesLikeThis
, and CONSTANT_VALUES_LIKE_THIS
.
Writing functions
Declare functions like this:
function_name = (arg1, opts) -> ...
function_with_no_args = -> ...
function_in_component: (arg1, arg2, opts) -> ...
Notice that functions which behave as members to a class should have the colon directly after the name.
Do not declare them like this:
bad_function:(args)->
badFunction : (arg1, arg2, arg3, arg4) ->
Functions should have a maximum of 3 arguments. Typically no more than 2. For more arguments, use the opts
pattern.
In general, if you ever find yourself wanting to use a default value for an argument, it's probably time to use opts
.
Use =>
or ->
? This has to do with scoping context at call time. There is (usually) a right answer.
Strings
We have (no?) stance on single quotes vs double quotes. However, do note that string interpolation in coffeescript only works using double quotes. ie.
For very long strings, use string concatenation to split it over long lines
Also, notice the break before the operator.
Or:
which also dedents the lines such that the string is actually ending up to be
Comments
[hsy]> how to comment functions, methods, ... ?
Callbacks
TODO