forked from wavded/gedit-coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.coffee
82 lines (61 loc) · 1.46 KB
/
test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Assignment
CONSTANT = 302
number = 42
opposite = true
# Conditions
number = -42 if opposite
# Functions
square = (x) -> x * x
# RegExp
matcher = /mymatch/g
matcher2 = url.match(///^([^?#]*)([^#]*)(.*)$///)
# Interpolation
html_double = "And the \" number is #{number}"
html_single = 'This is \' not an #{interpolation}'
# Heredocs
heredocs_double = """
Hello "world" and 'world' and #{number}
"""
heredocs_single = '''
Hello 'world' and "world" and not an #{interpolation}
'''
# Arrays
list = [1, 2, 3, 4, 5]
# Objects
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x
# Splats
race = (winners, runners...) ->
print winner, runners
# Existence
alert "I knew it!" if elvis?
# Array comprehensions
cubes = match.cube num for num in list
# Class
class Animal
constructor: (@name = '') ->
move: (meters) ->
alert @name + " moved " + meters + "m."
bud = new Animal
### Block
FIXME
Comments ###
### Single Line Comment ###
# Heregex
OPERATOR = /// ^ (
?: [-=]> # function
| [-+*/%<>&|^!?=]= # compound assign / compare
| >>>=? # zero-fill right shift
| ([-+:])\1 # doubles
| ([&|<>])\2=? # logic / shift
| \?\. # soak access
| \.{2,3}# # range or splat
) ///
$('#id').click (e) ->
$('#id').click ->
camel_cased_word.gsub /\.hello\/hi/, '/'
a = 'This is some string'
# Async control from IcedCoffeeScript variation
await someAsyncFunction 'param', defer response