Improvements to strings and comments docs; could be back-ported to v1 docs

This commit is contained in:
Geoffrey Booth 2016-12-18 15:13:54 -08:00
parent 58f9428c58
commit c8a3c1a6fd
3 changed files with 17 additions and 9 deletions

View File

@ -0,0 +1 @@
code = 2 * 617 # The code is 1234

View File

@ -0,0 +1,13 @@
## Comments
In CoffeeScript, comments are denoted by the `#` character. Everything from a `#` to the end of the line is ignored by the compiler, and will be excluded from the JavaScript output.
```
codeFor('comment')
```
Sometimes youd like to pass a block comment through to the generated JavaScript. For example, when you need to embed a licensing header at the top of a file. Block comments, which mirror the syntax for block strings, are preserved in the generated output.
```
codeFor('block_comment')
```

View File

@ -1,6 +1,6 @@
## String Interpolation, Block Strings, and Block Comments
## Strings
Ruby-style string interpolation is included in CoffeeScript. Double-quoted strings allow for interpolated values, using `#{ … }`, and single-quoted strings are literal. You may even use interpolation in object keys.
Like JavaScript and many other languages, CoffeeScript supports strings as delimited by the `"` or `'` characters. CoffeeScript also supports string interpolation within `"`-quoted strings, using `#{ … }`. Single-quoted strings are literal. You may even use interpolation in object keys.
```
codeFor('interpolation', 'sentence')
@ -12,16 +12,10 @@ Multiline strings are allowed in CoffeeScript. Lines are joined by a single spac
codeFor('strings', 'mobyDick')
```
Block strings can be used to hold formatted or indentation-sensitive text (or, if you just dont feel like escaping quotes and apostrophes). The indentation level that begins the block is maintained throughout, so you can keep it all aligned with the body of your code.
Block strings, delimited by `"""` or `'''`, can be used to hold formatted or indentation-sensitive text (or, if you just dont feel like escaping quotes and apostrophes). The indentation level that begins the block is maintained throughout, so you can keep it all aligned with the body of your code.
```
codeFor('heredocs', 'html')
```
Double-quoted block strings, like other double-quoted strings, allow interpolation.
Sometimes youd like to pass a block comment through to the generated JavaScript. For example, when you need to embed a licensing header at the top of a file. Block comments, which mirror the syntax for block strings, are preserved in the generated code.
```
codeFor('block_comment')
```