| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 4 |
<title>test.coffee</title> |
| 5 |
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (CoffeeScript) - Theme (Breeze Light)"/> |
| 6 |
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre> |
| 7 |
<span style="color:#898887;"># CoffeeScript test</span> |
| 8 |
<span style="color:#898887;"># Source: https://coffeescript.org</span> |
| 9 |
|
| 10 |
<span style="color:#898887;">### Multiline</span> |
| 11 |
<span style="color:#898887;"> comment ###</span> |
| 12 |
<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;">import</span> <span style="color:#bf0303;">'local-file.coffee'</span> |
| 13 |
|
| 14 |
<span style="color:#898887;"># Assignment:</span> |
| 15 |
number <span style="font-weight:bold;">=</span> <span style="color:#b08000;">42</span> |
| 16 |
opposite <span style="font-weight:bold;">=</span> <span style="color:#006e28;">true</span> |
| 17 |
|
| 18 |
<span style="color:#898887;"># Conditions:</span> |
| 19 |
number <span style="font-weight:bold;">=</span> <span style="font-weight:bold;">-</span><span style="color:#b08000;">42</span> <span style="font-weight:bold;">if</span> opposite |
| 20 |
|
| 21 |
<span style="color:#898887;"># Functions:</span> |
| 22 |
square <span style="font-weight:bold;">=</span> <span style="color:#644a9b;">(x) -></span> x <span style="font-weight:bold;">*</span> x |
| 23 |
|
| 24 |
<span style="color:#898887;"># Arrays:</span> |
| 25 |
list <span style="font-weight:bold;">=</span> <span style="font-weight:bold;">[</span><span style="color:#b08000;">1</span><span style="font-weight:bold;">,</span> <span style="color:#b08000;">2</span><span style="font-weight:bold;">,</span> <span style="color:#b08000;">3</span><span style="font-weight:bold;">,</span> <span style="color:#b08000;">4</span><span style="font-weight:bold;">,</span> <span style="color:#b08000;">5</span><span style="font-weight:bold;">]</span> |
| 26 |
|
| 27 |
<span style="color:#898887;"># Objects:</span> |
| 28 |
math <span style="font-weight:bold;">=</span> |
| 29 |
root<span style="font-weight:bold;">:</span> <span style="color:#006e28;">Math</span><span style="font-weight:bold;">.</span>sqrt |
| 30 |
square<span style="font-weight:bold;">:</span> square |
| 31 |
cube<span style="font-weight:bold;">:</span> <span style="color:#644a9b;">(x) -></span> x <span style="font-weight:bold;">*</span> square x |
| 32 |
|
| 33 |
<span style="color:#898887;"># Splats:</span> |
| 34 |
race <span style="font-weight:bold;">=</span> <span style="color:#644a9b;">(winner, runners...) -></span> |
| 35 |
print winner<span style="font-weight:bold;">,</span> runners |
| 36 |
|
| 37 |
<span style="color:#898887;"># Existence:</span> |
| 38 |
alert <span style="color:#bf0303;">"I knew it!"</span> <span style="font-weight:bold;">if</span> elvis<span style="font-weight:bold;">?</span> |
| 39 |
|
| 40 |
<span style="color:#898887;"># Array comprehensions:</span> |
| 41 |
cubes <span style="font-weight:bold;">=</span> <span style="font-weight:bold;">(</span>math<span style="font-weight:bold;">.</span>cube num <span style="font-weight:bold;">for</span> num <span style="font-weight:bold;">in</span> list<span style="font-weight:bold;">)</span> |
| 42 |
|
| 43 |
<span style="color:#898887;"># Classes:</span> |
| 44 |
<span style="font-weight:bold;">class</span> <span style="color:#0057ae;font-weight:bold;">Animal</span> |
| 45 |
<span style="font-weight:bold;">constructor</span><span style="font-weight:bold;">:</span> <span style="color:#644a9b;">(@name) -></span> |
| 46 |
|
| 47 |
move<span style="font-weight:bold;">:</span> <span style="color:#644a9b;">(meters) -></span> |
| 48 |
alert <span style="color:#0057ae;">@name</span> <span style="font-weight:bold;">+</span> <span style="color:#bf0303;">" moved </span><span style="color:#924c9d;">#{</span>meters<span style="color:#924c9d;">}</span><span style="color:#bf0303;">m."</span> |
| 49 |
|
| 50 |
<span style="color:#898887;"># Switch/When/Else:</span> |
| 51 |
<span style="font-weight:bold;">switch</span> day |
| 52 |
<span style="font-weight:bold;">when</span> <span style="color:#bf0303;">"Mon"</span> <span style="font-weight:bold;">then</span> go work |
| 53 |
<span style="font-weight:bold;">when</span> <span style="color:#bf0303;">"Tue"</span> <span style="font-weight:bold;">then</span> go relax |
| 54 |
<span style="font-weight:bold;">when</span> <span style="color:#bf0303;">"Thu"</span> <span style="font-weight:bold;">then</span> go iceFishing |
| 55 |
<span style="font-weight:bold;">when</span> <span style="color:#bf0303;">"Fri"</span><span style="font-weight:bold;">,</span> <span style="color:#bf0303;">"Sat"</span> |
| 56 |
<span style="font-weight:bold;">if</span> day <span style="font-weight:bold;">is</span> bingoDay |
| 57 |
go bingo |
| 58 |
go dancing |
| 59 |
<span style="font-weight:bold;">when</span> <span style="color:#bf0303;">"Sun"</span> <span style="font-weight:bold;">then</span> go church |
| 60 |
<span style="font-weight:bold;">else</span> go work |
| 61 |
|
| 62 |
<span style="color:#898887;"># Member objects:</span> |
| 63 |
<span style="color:#006e28;">Object</span><span style="font-weight:bold;">.</span>prop<span style="font-weight:bold;">.</span> Object <span style="font-weight:bold;">.</span>Object <span style="color:#006e28;">Object</span> |
| 64 |
timelineEvent<span style="font-weight:bold;">.</span>class |
| 65 |
|
| 66 |
<span style="color:#898887;"># Embedded JavaScript Code</span> |
| 67 |
markdown <span style="font-weight:bold;">=</span> <span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span><span style="font-weight:bold;">function</span> () { |
| 68 |
<span style="color:#644a9b;">return</span> <span style="color:#e31616;">\`In Markdown, write code like </span><span style="color:#3daee9;">\\\`</span><span style="color:#e31616;">this</span><span style="color:#3daee9;">\\\`</span><span style="color:#e31616;">\`</span><span style="color:#ca60ca;">;</span> |
| 69 |
}<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> |
| 70 |
|
| 71 |
<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">```</span> |
| 72 |
<span style="color:#898887;">// Comment</span> |
| 73 |
<span style="font-weight:bold;">var</span> array <span style="color:#ca60ca;">=</span> <span style="font-weight:bold;">new</span> <span style="color:#644a9b;font-weight:bold;">Array</span>(<span style="color:#b08000;">500</span>)<span style="color:#ca60ca;">;</span> |
| 74 |
<span style="font-weight:bold;">var</span> name <span style="color:#ca60ca;">=</span> <span style="color:#bf0303;">"Willy"</span><span style="color:#ca60ca;">;</span> |
| 75 |
<span style="color:#644a9b;">alert</span>(<span style="color:#e31616;">`Hello </span><span style="color:#3daee9;">${</span>name<span style="color:#3daee9;">}</span><span style="color:#e31616;">!`</span>)<span style="color:#ca60ca;">;</span> |
| 76 |
<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">```</span> |
| 77 |
<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> <span style="color:#644a9b;font-weight:bold;">String</span><span style="color:#ca60ca;">.</span><span style="color:#644a9b;">raw</span><span style="color:#e31616;">\`String ${x} \`</span> <span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> |
| 78 |
|
| 79 |
<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> <span style="color:#898887;">// Regular Expression after template</span> |
| 80 |
<span style="font-weight:bold;">const</span> a <span style="color:#ca60ca;">=</span> <span style="color:#e31616;">\`6\`</span> <span style="color:#ca60ca;">/</span> <span style="color:#b08000;">2</span><span style="color:#ca60ca;">;</span> <span style="color:#898887;">/*comment*/</span> |
| 81 |
<span style="color:#e31616;">\`template\`</span> <span style="color:#ff5500;">/regex/</span> <span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> |
| 82 |
|
| 83 |
<span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> <span style="color:#898887;">// Tagged template literals</span> |
| 84 |
<span style="color:#644a9b;">tagFunc</span><span style="color:#e31616;">\`Setting </span><span style="color:#3daee9;">${</span>setting<span style="color:#3daee9;">}</span><span style="color:#e31616;"> is </span><span style="color:#3daee9;">${</span>value<span style="color:#3daee9;">}</span><span style="color:#e31616;">!\`</span> <span style="color:#bf0303;background-color:#f7e6e6;font-weight:bold;font-style:italic;">`</span> |
| 85 |
</pre></body></html> |