1# CoffeeScript test 2# Source: https://coffeescript.org 3 4### Multiline 5 comment ### 6import 'local-file.coffee' 7 8# Assignment: 9number = 42 10opposite = true 11 12# Conditions: 13number = -42 if opposite 14 15# Functions: 16square = (x) -> x * x 17 18# Arrays: 19list = [1, 2, 3, 4, 5] 20 21# Objects: 22math = 23 root: Math.sqrt 24 square: square 25 cube: (x) -> x * square x 26 27# Splats: 28race = (winner, runners...) -> 29 print winner, runners 30 31# Existence: 32alert "I knew it!" if elvis? 33 34# Array comprehensions: 35cubes = (math.cube num for num in list) 36 37# Classes: 38class Animal 39 constructor: (@name) -> 40 41 move: (meters) -> 42 alert @name + " moved #{meters}m." 43 44# Switch/When/Else: 45switch day 46 when "Mon" then go work 47 when "Tue" then go relax 48 when "Thu" then go iceFishing 49 when "Fri", "Sat" 50 if day is bingoDay 51 go bingo 52 go dancing 53 when "Sun" then go church 54 else go work 55 56# Member objects: 57Object.prop. Object .Object Object 58timelineEvent.class 59 60# Embedded JavaScript Code 61markdown = `function () { 62 return \`In Markdown, write code like \\\`this\\\`\`; 63}` 64 65``` 66 // Comment 67 var array = new Array(500); 68 var name = "Willy"; 69 alert(`Hello ${name}!`); 70``` 71` String.raw\`String ${x} \` ` 72 73` // Regular Expression after template 74 const a = \`6\` / 2; /*comment*/ 75 \`template\` /regex/ ` 76 77` // Tagged template literals 78 tagFunc\`Setting ${setting} is ${value}!\` ` 79