forked from jashkenas/coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
6676 lines (5807 loc) · 463 KB
/
index.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>CoffeeScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="canonical" href="https://coffeescript.org" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="theme-color" content="#ffffff">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<!-- The CoffeeScript logo font is Google’s Galada -->
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans:400,800|Lato:300,300i,400,700|Roboto+Mono:400,400i" rel="stylesheet" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.css" rel="stylesheet" crossorigin="anonymous">
<style>
/* Adapted from https://github.com/FarhadG/code-mirror-themes/blob/master/themes/twilight.css and https://github.com/codemirror/CodeMirror/blob/master/theme/twilight.css */
/* CodeMirror general styling */
.CodeMirror,
.placeholder-code {
/* https://codemirror.net/demo/resize.html */
height: auto;
background: transparent;
font-family: 'Roboto Mono';
font-weight: 400;
line-height: 1.25;
letter-spacing: 0.3px;
color: #f8f8f8;
/* Prevent mobile Safari from zooming in on our code editors; the code is 16px naturally, but somehow being explicit about it prevents the zooming */
font-size: 16px;
}
@media (min-width: 768px) {
.CodeMirror,
.placeholder-code {
font-size: 87.5%; /* Matching Bootstrap’s font size for code, which calculates to 14.4px */
}
}
.CodeMirror-lines {
padding: 0.5em 0;
}
.placeholder-code {
padding: 0.5em 4px;
margin-bottom: 1.37em;
white-space: pre-wrap;
}
.CodeMirror pre,
pre.placeholder-code {
line-height: 1.4em;
}
.CodeMirror-code:focus {
outline: none;
}
div.CodeMirror-cursor {
border-left: 3px solid #f8f8f8;
}
.CodeMirror-activeline-background {
background: #ffffff08;
}
.CodeMirror-selected {
background: #ddf0ff33;
}
/* Syntax highlighting */
.cm-keyword,
.placeholder-code .keyword {
color: #cda869;
}
.cm-atom {
color: #dad085;
}
.cm-number,
.cm-meta,
.placeholder-code .number,
.placeholder-code .built_in,
.placeholder-code .builtin-name,
.placeholder-code .literal,
.placeholder-code .type,
/*.placeholder-code .params,*/
.placeholder-code .meta,
.placeholder-code .link {
color: #dad085;
}
.cm-def {
color: #f8f8f8;
}
span.cm-variable-2,
span.cm-tag {
color: #f8f8f8;
}
span.cm-variable-3,
span.cm-def,
span.cm-type {
color: #f8f8f8;
}
.cm-operator,
.placeholder-code .punctuation,
.placeholder-code .symbol,
.placeholder-code .bullet,
.placeholder-code .addition,
.placeholder-code .operator {
color: #cda869;
}
.cm-comment,
.placeholder-code .comment {
font-style: italic;
color: #5f5a60;
}
.cm-string,
.cm-string-2,
.placeholder-code .string {
color: #8f9d6a;
}
.cm-property,
.placeholder-code .attribute {
color: #dad085;
}
.cm-builtin {
color: #cda869;
}
.cm-tag {
color: #997643;
}
.cm-attribute {
color: #d6bb6d;
}
.cm-header {
color: #FF6400;
}
.cm-hr {
color: #AEAEAE;
}
.cm-link {
color: #ad9361;
font-style: italic;
text-decoration: none;
}
.cm-error {
border-bottom: 1px solid rgba(142, 22, 22, 0.67);
}
/* Uneditable code blocks are inverted, so use darker versions of the above */
.uneditable-code-block code {
padding: 0;
}
.uneditable-code-block .comment {
font-style: italic;
color: #837B85;
}
.uneditable-code-block .class,
.uneditable-code-block .function,
.uneditable-code-block .keyword,
.uneditable-code-block .reserved,
.uneditable-code-block .title {
color: #534328;
}
.uneditable-code-block .string
.uneditable-code-block .value
.uneditable-code-block .inheritance
.uneditable-code-block .header {
color: #3A4029;
}
.uneditable-code-block .variable,
.uneditable-code-block .literal,
.uneditable-code-block .tag,
.uneditable-code-block .regexp,
.uneditable-code-block .subst,
.uneditable-code-block .property {
color: #474429;
}
.uneditable-code-block .number,
.uneditable-code-block .preprocessor,
.uneditable-code-block .built_in,
.uneditable-code-block .params,
.uneditable-code-block .constant {
color: #474429;
}
html,
body {
/* Prevent scroll on narrow devices */
overflow-x: hidden;
}
body {
/* Required for Scrollspy */
position: relative;
/* Push below header bar */
margin-top: 3.5rem;
}
svg {
width: auto;
height: 100%;
}
a {
color: #1b5e20;
transition: 0.1s ease-in-out;
}
a:focus, a:hover, a:active {
color: #388e3c;
cursor: pointer;
text-decoration: none;
}
button:focus, .navbar-dark .navbar-toggler:focus {
outline: none;
border: thin solid rgba(248, 243, 240, 0.3);
}
.bg-dark {
background-color: #3e2723 !important;
}
.bg-ribbed-light {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 3"><path opacity=".03" fill="#000" d="M0 0h1v1H0z"/><path opacity=".005" fill="#000" d="M0 1h1v2H0z"/></svg>');
background-size: 1px 3px;
}
.bg-ribbed-dark {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 3"><path opacity=".2" fill="#000" d="M0 0h1v1H0z"/><path opacity=".15" fill="#000" d="M0 1h1v2H0z"/></svg>');
background-size: 1px 3px;
}
/*
* Header
*/
.site-navbar {
height: 3.5rem;
font-family: 'Lato';
font-weight: 400;
font-size: 1.1em;
}
.navbar-brand {
height: 2.2em;
margin-right: 1em;
}
.navbar-dark path {
fill: #fff;
}
.navbar-nav .nav-item {
margin-left: 0.6em;
margin-right: 0.6em;
border-radius: 0.4em;
}
.navbar-nav .nav-item:hover,
.navbar-nav .nav-item:active,
.navbar-nav .nav-item.show {
background-color: #4e342e;
}
.navbar-toggler {
transition: all 0.1s ease-in-out;
}
/*
* Layout; based on https://codepen.io/Sphinxxxx/pen/WjwbEO
*/
.main-row {
height: calc(100vh - 3.5rem);
}
/*
* Sidebar
*/
.sidebar {
/* Scrollable contents if viewport is shorter than content */
overflow-y: auto;
overflow-x: hidden;
left: 0;
bottom: 0;
z-index: 1000;
padding: 0;
background-color: #efebe9;
border-right: 1px solid #efebe9;
}
.sidebar::-webkit-scrollbar {
display: none;
}
@media screen and (max-width: 991px) {
.sidebar {
position: fixed;
top: 3.5em;
height: calc(100% - 3.5rem);
left: -100%;
transition: 0.25s left ease-in-out;
}
.sidebar.show {
left: 0;
}
}
@media (min-width: 992px) {
.sidebar {
flex: 0 0 auto;
}
}
.contents {
padding: 0.5em 0 0.5em 0.5em;
font-family: 'Alegreya Sans';
font-weight: 400;
font-size: 1.2em;
align-items: normal;
}
.contents .nav .nav {
margin-left: 1em;
font-size: 0.9em;
}
.contents .nav-link {
padding: 0.2em 0.7em;
}
.contents .nav-link.active,
.contents .nav-link.active a:hover,
.contents .nav-link.active a:focus {
font-weight: 800;
}
/*
* Main content
*/
.main {
max-width: 100%;
padding: 1.3em;
}
@media (min-width: 992px) {
.main {
flex: 1 1 auto;
overflow: auto;
padding-right: 2em;
padding-left: 2em;
}
}
.title-logo {
width: 30rem;
margin: 3rem auto;
}
.title-logo path {
fill: #2f2625;
}
.main p, .main li, .main td, .main th {
font-family: Lato;
font-weight: 300;
font-size: 1.1em;
line-height: 1.7;
}
.main blockquote {
font-size: 1.1em;
}
.main li p, .main li li, .main li blockquote {
font-size: 1em;
}
@media (min-width: 768px) {
.main p, .main li, .main td, .main th, .main blockquote {
font-size: 1.2em;
}
}
.main td {
vertical-align: top;
padding: 0.3em 0;
}
.main strong, .main th {
font-weight: 700;
}
.main a {
border-bottom: 2px solid transparent;
font-weight: 400;
}
.main a:focus, .main a:hover, .main a:active {
border-bottom: 2px solid rgba(56, 142, 60, 0.2);
}
.main blockquote pre {
background-color: #f8f3f0;
color: #2f2625;
border-radius: .3em;
padding: 0.4em 0.6em;
}
p, blockquote, table, .code-example {
margin-bottom: 1.1em;
}
.main li {
margin-bottom: 0.6em;
}
code, td code {
white-space: nowrap;
padding: 2px 8px;
}
pre code {
white-space: pre; /* We want newlines to be newlines in code blocks */
}
h2, h3, h4 {
margin-top: 1.3em;
margin-bottom: 0.6em;
font-family: 'Alegreya Sans';
}
h2 {
font-weight: 800;
}
h3, h4, h2 time {
font-weight: 400;
}
@media (min-width: 1200px) {
.main > header, .main section > h2, .main section > h3, .main section > h4, .main section > p, .main section > blockquote, .main section > ul, .main section > table {
max-width: 80%;
}
}
code, button {
font-family: 'Roboto Mono';
font-weight: 400;
}
code, a > code {
background-color: #f8f3f0;
}
code {
color: #2f2625;
}
/*
* Chrome around code examples; see code.css for the styling of the code blocks themselves
*/
textarea {
position: absolute;
left: -99999px; /* Hide off canvas, while still remaining visible */
}
.code-example {
background-color: #2f2625;
padding: 1em;
border-radius: 0.3em;
margin-bottom: 1em;
}
.javascript-output-column {
border-left: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-primary {
background-color: #69f0ae;
color: #0b140f;
border-color: #53d88f;
transition: 0.2s ease-in-out;
min-width: 3.125rem;
}
.btn-primary:active, .btn-primary:focus, .btn-primary:hover, .btn-primary:active:hover, .btn-primary:active:focus {
background-color: #61fea8;
color: #060a08;
border-color: #4de486;
outline: 0;
}
.play-button {
height: 1em;
width: 1em;
}
.javascript-output-column .CodeMirror-cursor {
/* https://github.com/codemirror/CodeMirror/issues/2568 */
display: none;
}
/*
* Try CoffeeScript
*/
.try-coffeescript {
position: fixed;
height: calc(100% - 3.5rem);
top: 3.5rem;
left: 0;
right: 0;
opacity: 0;
transition: opacity 0.15s ease-in-out;
z-index: -1001;
background-color: #2f2625;
}
.try-coffeescript.show {
opacity: 1;
z-index: 1001;
}
.try-coffeescript .CodeMirror {
height: calc(100vh - 7rem);
cursor: text;
}
.try-coffeescript .code-column {
overflow: hidden;
background-color: #2f2625;
color: #2f2625;
}
@media screen and (max-width: 767px) {
.try-coffeescript .code-column {
height: calc(50vh - 0.5 * 3.5rem);
}
}
@media screen and (min-width: 768px) {
.try-coffeescript .code-column {
padding-bottom: 100%;
margin-bottom: -100%;
}
}
.try-coffeescript button svg {
height: 1em;
transform: scale(1.3) translateY(0.1em);
fill: #0b140f;
}
@media screen and (max-width: 767px) {
.try-coffeescript .try-buttons {
position: absolute;
bottom: 1em;
z-index: 1002;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark bg-ribbed-dark site-navbar">
<a class="navbar-brand" href="#" data-close="try" data-action="scroll-to-top"><svg xmlns="http://www.w3.org/2000/svg" viewBox="-22 347 566 100">
<title>
CoffeeScript Logo
</title>
<path d="M21.7 351.1c.1.6-.2 1.1-1.2 1.6-1.3-.7-4.1-1.1-6.4-.9-2.5.2-4.6 1-4.3 2.7.4 1.7 2.8 2.7 7.1 2.3 10.5-.9 10.4-8 25.8-9.4 12-1.1 18.7 2.6 19.6 7.1.7 3.5-2.2 6.9-10.9 7.6-7.7.7-12.2-1.4-12.6-3.5-.2-1.1.4-2.7 4.1-3.1.4 1.7 2.5 3.5 7.5 3 3.6-.3 6.6-1.6 6.2-3.6-.4-2.1-4.2-3.3-10.2-2.8-12.2 1.1-15.2 7.8-25.6 8.7-7.4.7-13.4-2-14.2-6-.3-1.5-.3-5 7.5-5.7 4-.3 7.2.4 7.6 2zm-39 41.8c-3.4 4.3-4.9 9.3-4.6 14.2.3 4.9 2.7 8.9 6.5 12 4 3.1 8.3 4 13.2 3.1 1.9-.3 4-1.3 5.9-1.9-4 0-7.4-1.3-10.8-4-3.7-2.7-6.2-6.5-6.8-11.1-.9-4.3 0-8.3 2.4-11.8 2.7-3.4 6.2-5.3 10.8-5.9 4.6-.3 8.6.9 12.6 3.7-.9-1.3-2.2-2.2-3.4-3.4-4-2.7-8.3-4-13.6-2.7-4.8 1-8.8 3.5-12.2 7.8zm53.6-23.1c-12.9 0-24.4-1.3-32.7-3.1-8.9-2.2-13.6-4.6-13.6-7.7 0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.8-19.1 16.8-5.5 0-9.7-3.2-9.7-10.9 0-1.8.3-3.7.7-5.9l6.2-29.2 13.3.1zm-4.1-19.4c4 0 7.2 3.2 7.2 7.2s-3.2 7.1-7.2 7.1-7.1-3.1-7.1-7.1c-.1-4 3.2-7.2 7.1-7.2zm29.1 16l-1.5 6.9c2.6-2.3 6.1-3.9 10.7-3.9 6.2 0 11.1 3.5 11.1 14.4 0 12.2-4.7 32.1-22.3 32.1-4.5 0-6.8-1.6-7.7-3.2l-4.7 22.1-13.7 3.2 15.2-71.5 12.9-.1zm7.8 17c0-7-2.9-7.5-4.5-7.5-2 0-4.5 1.6-6.3 4.4l-5.4 25.5c.4 1 1.4 2.1 3.4 2.1 9.7 0 12.8-15.9 12.8-24.5zm27.8 17.3c-.3 1.1-.5 2.2-.5 3.1 0 1.9.7 3.2 3.1 3.2.7 0 1.7 0 2.4-.3-2.5 7.8-6.6 8.9-9.6 8.9-6.4 0-9.1-4.4-9.1-10.3 0-1.6.2-3.1.6-4.8l5.8-27.2h-3l.7-3.6h3L528 366l13.4-1.9s-1.4 6.2-3.1 14.4h5.5l-.7 3.6h-5.5l-5.7 27.4z"></path>
</svg>
</a>
<button class="navbar-toggler" type="button" data-toggle="offcanvas" data-close="try" aria-label="Toggle sidebar">
<span class="navbar-toggler-icon"></span>
</button>
<nav class="collapse navbar-collapse">
<div class="navbar-nav mr-auto d-none d-lg-flex">
<a href="#try" id="try-link" class="nav-item nav-link" data-toggle="try">Try CoffeeScript</a>
<a href="#language" class="nav-item nav-link" data-close="try">Language Reference</a>
<a href="#integrations" class="nav-item nav-link" data-close="try">Integrations</a>
<a href="#resources" class="nav-item nav-link" data-close="try">Resources</a>
<a href="https://github.com/jashkenas/coffeescript/" class="nav-item nav-link" data-close="try">GitHub
</a>
</div>
</nav>
</nav>
<aside id="try" class="try-coffeescript container-fluid" data-example="try">
<div class="row">
<div class="col-md-6 code-column bg-ribbed-dark coffeescript-input-column">
<textarea class="coffeescript-input" id="try-coffeescript-coffee">alert 'Hello CoffeeScript!'</textarea>
</div>
<div class="col-md-6 code-column bg-ribbed-dark javascript-output-column">
<textarea class="javascript-output" id="try-coffeescript-js">alert('Hello CoffeeScript!');</textarea>
</div>
</div>
<div class="row">
<div class="col text-right try-buttons">
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="try-coffeescript" data-run="true"><svg class="play-button" viewBox="0 0 24 24">
<path d="M2.56-0.01v24.02L21.44 11.98 2.56-0.01z"></path>
</svg>
</button> 
</div>
</div>
</aside>
<div class="container-fluid" id="top">
<div class="row flex-nowrap main-row">
<nav class="sidebar bg-ribbed-light">
<nav id="contents" class="navbar contents">
<nav class="nav flex-column">
<a href="#try" class="nav-link d-md-none" data-action="sidebar-nav" data-toggle="try">Try CoffeeScript</a>
<a href="#introduction" class="nav-link" data-action="sidebar-nav">Introduction</a>
<a href="#overview" class="nav-link" data-action="sidebar-nav">Overview</a>
<a href="#coffeescript-2" class="nav-link" data-action="sidebar-nav">CoffeeScript 2</a>
<nav class="nav flex-column">
<a href="#whats-new-in-coffeescript-2" class="nav-link" data-action="sidebar-nav">What’s New in CoffeeScript 2</a>
<a href="#compatibility" class="nav-link" data-action="sidebar-nav">Compatibility</a>
</nav>
<a href="#installation" class="nav-link" data-action="sidebar-nav">Installation</a>
<a href="#usage" class="nav-link" data-action="sidebar-nav">Usage</a>
<nav class="nav flex-column">
<a href="#cli" class="nav-link" data-action="sidebar-nav">Command Line</a>
<a href="#nodejs-usage" class="nav-link" data-action="sidebar-nav">Node.js</a>
<a href="#transpilation" class="nav-link" data-action="sidebar-nav">Transpilation</a>
</nav>
<a href="#language" class="nav-link" data-action="sidebar-nav">Language Reference</a>
<nav class="nav flex-column">
<a href="#functions" class="nav-link" data-action="sidebar-nav">Functions</a>
<a href="#strings" class="nav-link" data-action="sidebar-nav">Strings</a>
<a href="#objects-and-arrays" class="nav-link" data-action="sidebar-nav">Objects and Arrays</a>
<a href="#comments" class="nav-link" data-action="sidebar-nav">Comments</a>
<a href="#lexical-scope" class="nav-link" data-action="sidebar-nav">Lexical Scoping and Variable Safety</a>
<a href="#conditionals" class="nav-link" data-action="sidebar-nav">If, Else, Unless, and Conditional Assignment</a>
<a href="#splats" class="nav-link" data-action="sidebar-nav">Splats, or Rest Parameters/Spread Syntax</a>
<a href="#loops" class="nav-link" data-action="sidebar-nav">Loops and Comprehensions</a>
<a href="#slices" class="nav-link" data-action="sidebar-nav">Array Slicing and Splicing</a>
<a href="#expressions" class="nav-link" data-action="sidebar-nav">Everything is an Expression</a>
<a href="#operators" class="nav-link" data-action="sidebar-nav">Operators and Aliases</a>
<a href="#existential-operator" class="nav-link" data-action="sidebar-nav">Existential Operator</a>
<a href="#destructuring" class="nav-link" data-action="sidebar-nav">Destructuring Assignment</a>
<a href="#chaining" class="nav-link" data-action="sidebar-nav">Chaining Function Calls</a>
<a href="#fat-arrow" class="nav-link" data-action="sidebar-nav">Bound (Fat Arrow) Functions</a>
<a href="#generators" class="nav-link" data-action="sidebar-nav">Generator Functions</a>
<a href="#async-functions" class="nav-link" data-action="sidebar-nav">Async Functions</a>
<a href="#classes" class="nav-link" data-action="sidebar-nav">Classes</a>
<a href="#prototypal-inheritance" class="nav-link" data-action="sidebar-nav">Prototypal Inheritance</a>
<a href="#switch" class="nav-link" data-action="sidebar-nav">Switch/When/Else</a>
<a href="#try-catch" class="nav-link" data-action="sidebar-nav">Try/Catch/Finally</a>
<a href="#comparisons" class="nav-link" data-action="sidebar-nav">Chained Comparisons</a>
<a href="#regexes" class="nav-link" data-action="sidebar-nav">Block Regular Expressions</a>
<a href="#tagged-template-literals" class="nav-link" data-action="sidebar-nav">Tagged Template Literals</a>
<a href="#modules" class="nav-link" data-action="sidebar-nav">Modules</a>
<a href="#embedded" class="nav-link" data-action="sidebar-nav">Embedded JavaScript</a>
<a href="#jsx" class="nav-link" data-action="sidebar-nav">JSX</a>
</nav>
<a href="#type-annotations" class="nav-link" data-action="sidebar-nav">Type Annotations</a>
<a href="#literate" class="nav-link" data-action="sidebar-nav">Literate CoffeeScript</a>
<a href="#source-maps" class="nav-link" data-action="sidebar-nav">Source Maps</a>
<a href="#cake" class="nav-link" data-action="sidebar-nav">Cake, and Cakefiles</a>
<a href="#scripts" class="nav-link" data-action="sidebar-nav"><code>"text/coffeescript"</code> Script Tags</a>
<a href="#integrations" class="nav-link" data-action="sidebar-nav">Integrations</a>
<nav class="nav flex-column">
<a href="#build-tools" class="nav-link" data-action="sidebar-nav">Build Tools</a>
<a href="#code-editors" class="nav-link" data-action="sidebar-nav">Code Editors</a>
<a href="#frameworks" class="nav-link" data-action="sidebar-nav">Frameworks</a>
<a href="#linters-and-formatting" class="nav-link" data-action="sidebar-nav">Linters and Formatting</a>
<a href="#testing" class="nav-link" data-action="sidebar-nav">Testing</a>
</nav>
<a href="#resources" class="nav-link" data-action="sidebar-nav">Resources</a>
<nav class="nav flex-column">
<a href="#books" class="nav-link" data-action="sidebar-nav">Books</a>
<a href="#screencasts" class="nav-link" data-action="sidebar-nav">Screencasts</a>
<a href="#examples" class="nav-link" data-action="sidebar-nav">Examples</a>
<a href="#chat" class="nav-link" data-action="sidebar-nav">Chat</a>
<a href="#annotated-source" class="nav-link" data-action="sidebar-nav">Annotated Source</a>
<a href="#contributing" class="nav-link" data-action="sidebar-nav">Contributing</a>
</nav>
<a href="https://github.com/jashkenas/coffeescript/" class="nav-item nav-link d-md-none" data-action="sidebar-nav">GitHub</a>
<a href="#unsupported" class="nav-link" data-action="sidebar-nav">Unsupported ECMAScript Features</a>
<nav class="nav flex-column">
<a href="#unsupported-let-const" class="nav-link" data-action="sidebar-nav"><code>let</code> and <code>const</code></a>
<a href="#unsupported-named-functions" class="nav-link" data-action="sidebar-nav">Named Functions and Function Declarations</a>
<a href="#unsupported-get-set" class="nav-link" data-action="sidebar-nav"><code>get</code> and <code>set</code> Shorthand Syntax</a>
</nav>
<a href="#breaking-changes" class="nav-link" data-action="sidebar-nav">Breaking Changes From 1.x</a>
<nav class="nav flex-column">
<a href="#breaking-changes-fat-arrow" class="nav-link" data-action="sidebar-nav">Bound (Fat Arrow) Functions</a>
<a href="#breaking-changes-default-values" class="nav-link" data-action="sidebar-nav">Default Values</a>
<a href="#breaking-changes-bound-generator-functions" class="nav-link" data-action="sidebar-nav">Bound Generator Functions</a>
<a href="#breaking-changes-classes" class="nav-link" data-action="sidebar-nav">Classes</a>
<a href="#breaking-changes-super-this" class="nav-link" data-action="sidebar-nav"><code>super</code> and <code>this</code></a>
<a href="#breaking-changes-super-extends" class="nav-link" data-action="sidebar-nav"><code>super</code> and <code>extends</code></a>
<a href="#breaking-changes-jsx-and-the-less-than-and-greater-than-operators" class="nav-link" data-action="sidebar-nav">JSX and the <code><</code> and <code>></code> Operators</a>
<a href="#breaking-changes-literate-coffeescript" class="nav-link" data-action="sidebar-nav">Literate CoffeeScript Parsing</a>
<a href="#breaking-changes-argument-parsing-and-shebang-lines" class="nav-link" data-action="sidebar-nav">Argument Parsing and <code>#!</code> Lines</a>
</nav>
<a href="#changelog" class="nav-link" data-action="sidebar-nav">Changelog</a>
<a href="test.html" class="nav-link" data-action="sidebar-nav">Browser-Based Tests</a>
<a href="/v1/" class="nav-link" data-action="sidebar-nav">Version 1.x Documentation</a>
</nav>
</nav>
</nav>
<main class="main">
<header class="d-none d-lg-block">
<p class="title-logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-22 347 566 100">
<title>
CoffeeScript Logo
</title>
<path d="M21.7 351.1c.1.6-.2 1.1-1.2 1.6-1.3-.7-4.1-1.1-6.4-.9-2.5.2-4.6 1-4.3 2.7.4 1.7 2.8 2.7 7.1 2.3 10.5-.9 10.4-8 25.8-9.4 12-1.1 18.7 2.6 19.6 7.1.7 3.5-2.2 6.9-10.9 7.6-7.7.7-12.2-1.4-12.6-3.5-.2-1.1.4-2.7 4.1-3.1.4 1.7 2.5 3.5 7.5 3 3.6-.3 6.6-1.6 6.2-3.6-.4-2.1-4.2-3.3-10.2-2.8-12.2 1.1-15.2 7.8-25.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 16.8-25 16.8-8.5 0-14.2-4.2-14.2-14.5 0-10.6 6-32.3 24.5-32.3 8.1 0 10.1 4.2 10.1 8.3 0 4.4-2.2 6.7-4.8 6.7-1 0-2.1-.4-3.1-1.1.5-1.9.9-3.6.9-5.3zm27.7-7.6l-1.2 5.7c3.1-2.7 6.7-5.7 11-5.7 4.1 0 6.3 3.3 6.3 6.9 0 3.1-2.1 6.7-6.6 6.7-5.1 0-2.5-6-5.3-6-2.7 0-4.4 1.4-6.7 3.4l-7.2 34.6h-13.1l9.6-45.4 13.2-.2zm34.2 0l-6.6 30.9c-.3 1.2-.4 2.1-.4 2.9 0 2.5 1.2 3.3 3.7 3.3 3.5 0 6.9-3.4 8.1-8h3.8c-5.2 14.8-14.2 16.8-19.1 16.8-5.5 0-9.7-3.2-9.7-10.9 0-1.8.3-3.7.7-5.9l6.2-29.2 13.3.1zm-4.1-19.4c4 0 7.2 3.2 7.2 7.2s-3.2 7.1-7.2 7.1-7.1-3.1-7.1-7.1c-.1-4 3.2-7.2 7.1-7.2zm29.1 16l-1.5 6.9c2.6-2.3 6.1-3.9 10.7-3.9 6.2 0 11.1 3.5 11.1 14.4 0 12.2-4.7 32.1-22.3 32.1-4.5 0-6.8-1.6-7.7-3.2l-4.7 22.1-13.7 3.2 15.2-71.5 12.9-.1zm7.8 17c0-7-2.9-7.5-4.5-7.5-2 0-4.5 1.6-6.3 4.4l-5.4 25.5c.4 1 1.4 2.1 3.4 2.1 9.7 0 12.8-15.9 12.8-24.5zm27.8 17.3c-.3 1.1-.5 2.2-.5 3.1 0 1.9.7 3.2 3.1 3.2.7 0 1.7 0 2.4-.3-2.5 7.8-6.6 8.9-9.6 8.9-6.4 0-9.1-4.4-9.1-10.3 0-1.6.2-3.1.6-4.8l5.8-27.2h-3l.7-3.6h3L528 366l13.4-1.9s-1.4 6.2-3.1 14.4h5.5l-.7 3.6h-5.5l-5.7 27.4z"></path>
</svg>
</p>
</header>
<section id="introduction">
<p><strong>CoffeeScript is a little language that compiles into JavaScript.</strong> Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.</p>
<p>The golden rule of CoffeeScript is: <em>“It’s just JavaScript.”</em> The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable, pretty-printed, and tends to run as fast or faster than the equivalent handwritten JavaScript.</p>
<p><strong>Latest Version:</strong> <a href="https://github.com/jashkenas/coffeescript/tarball/2.6.1">2.6.1</a></p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash"><span class="comment"># Install locally for a project:</span>
npm install --save-dev coffeescript
<span class="comment"># Install globally to execute .coffee files anywhere:</span>
npm install --global coffeescript
</code></pre>
</blockquote>
</section>
<section id="overview">
<h2>Overview</h2>
<p><em>CoffeeScript on the <span class="d-md-none">top</span><span class="d-none d-md-inline">left</span>, compiled JavaScript output on the <span class="d-md-none">bottom</span><span class="d-none d-md-inline">right</span>. The CoffeeScript is editable!</em></p>
<aside class="code-example container-fluid bg-ribbed-dark" data-example="overview">
<div class="row">
<div class="col-md-6 coffeescript-input-column">
<textarea class="coffeescript-input" id="overview-coffee"># Assignment:
number = 42
opposite = true
# Conditions:
number = -42 if opposite
# Functions:
square = (x) -> x * x
# Arrays:
list = [1, 2, 3, 4, 5]
# Objects:
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x
# Splats:
race = (winner, runners...) ->
print winner, runners
# Existence:
alert "I knew it!" if elvis?
# Array comprehensions:
cubes = (math.cube num for num in list)
</textarea>
<pre class="placeholder-code"><span class="cm-comment"># Assignment:</span>
<span class="cm-variable">number</span> <span class="cm-punctuation">=</span> <span class="cm-number">42</span>
<span class="cm-variable">opposite</span> <span class="cm-punctuation">=</span> <span class="cm-atom">true</span>
<span class="cm-comment"># Conditions:</span>
<span class="cm-variable">number</span> <span class="cm-punctuation">=</span> <span class="cm-number">-42</span> <span class="cm-keyword">if</span> <span class="cm-variable">opposite</span>
<span class="cm-comment"># Functions:</span>
<span class="cm-variable">square</span> <span class="cm-punctuation">=</span> <span class="cm-punctuation">(</span><span class="cm-variable">x</span><span class="cm-punctuation">)</span> <span class="cm-operator">-></span> <span class="cm-variable">x</span> <span class="cm-operator">*</span> <span class="cm-variable">x</span>
<span class="cm-comment"># Arrays:</span>
<span class="cm-variable">list</span> <span class="cm-punctuation">=</span> <span class="cm-punctuation">[</span><span class="cm-number">1</span><span class="cm-punctuation">,</span> <span class="cm-number">2</span><span class="cm-punctuation">,</span> <span class="cm-number">3</span><span class="cm-punctuation">,</span> <span class="cm-number">4</span><span class="cm-punctuation">,</span> <span class="cm-number">5</span><span class="cm-punctuation">]</span>
<span class="cm-comment"># Objects:</span>
<span class="cm-variable">math</span> <span class="cm-punctuation">=</span>
<span class="cm-indent"> </span><span class="cm-variable">root</span><span class="cm-punctuation">:</span> <span class="cm-variable">Math</span><span class="cm-punctuation">.</span><span class="cm-property">sqrt</span>
<span class="cm-variable">square</span><span class="cm-punctuation">:</span> <span class="cm-variable">square</span>
<span class="cm-variable">cube</span><span class="cm-punctuation">:</span> <span class="cm-punctuation">(</span><span class="cm-variable">x</span><span class="cm-punctuation">)</span> <span class="cm-operator">-></span> <span class="cm-variable">x</span> <span class="cm-operator">*</span> <span class="cm-variable">square</span> <span class="cm-variable">x</span>
<span class="cm-comment"># Splats:</span>
<span class="cm-variable">race</span> <span class="cm-punctuation">=</span> <span class="cm-punctuation">(</span><span class="cm-variable">winner</span><span class="cm-punctuation">,</span> <span class="cm-variable">runners</span><span class="cm-punctuation">...)</span> <span class="cm-operator">-></span>
<span class="cm-variable">print</span> <span class="cm-variable">winner</span><span class="cm-punctuation">,</span> <span class="cm-variable">runners</span>
<span class="cm-comment"># Existence:</span>
<span class="cm-variable">alert</span> <span class="cm-string">"I knew it!"</span> <span class="cm-keyword">if</span> <span class="cm-variable">elvis</span><span class="cm-operator">?</span>
<span class="cm-comment"># Array comprehensions:</span>
<span class="cm-variable">cubes</span> <span class="cm-punctuation">=</span> <span class="cm-punctuation">(</span><span class="cm-variable">math</span><span class="cm-punctuation">.</span><span class="cm-property">cube</span> <span class="cm-variable">num</span> <span class="cm-keyword">for</span> <span class="cm-variable">num</span> <span class="cm-operator">in</span> <span class="cm-variable">list</span><span class="cm-punctuation">)</span>
</pre>
</div>
<div class="col-md-6 javascript-output-column">
<textarea class="javascript-output" id="overview-js">// Assignment:
var cubes, list, math, num, number, opposite, race, square;
number = 42;
opposite = true;
if (opposite) {
// Conditions:
number = -42;
}
// Functions:
square = function(x) {
return x * x;
};
// Arrays:
list = [1, 2, 3, 4, 5];
// Objects:
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
};
// Splats:
race = function(winner, ...runners) {
return print(winner, runners);
};
if (typeof elvis !== "undefined" && elvis !== null) {
// Existence:
alert("I knew it!");
}
// Array comprehensions:
cubes = (function() {
var i, len, results;
results = [];
for (i = 0, len = list.length; i < len; i++) {
num = list[i];
results.push(math.cube(num));
}
return results;
})();
</textarea>
<pre class="placeholder-code"><span class="cm-comment">// Assignment:</span>
<span class="cm-keyword">var</span> <span class="cm-def">cubes</span>, <span class="cm-def">list</span>, <span class="cm-def">math</span>, <span class="cm-def">num</span>, <span class="cm-def">number</span>, <span class="cm-def">opposite</span>, <span class="cm-def">race</span>, <span class="cm-def">square</span>;
<span class="cm-variable">number</span> <span class="cm-operator">=</span> <span class="cm-number">42</span>;
<span class="cm-variable">opposite</span> <span class="cm-operator">=</span> <span class="cm-atom">true</span>;
<span class="cm-keyword">if</span> (<span class="cm-variable">opposite</span>) {
<span class="cm-comment">// Conditions:</span>
<span class="cm-variable">number</span> <span class="cm-operator">=</span> <span class="cm-operator">-</span><span class="cm-number">42</span>;
}
<span class="cm-comment">// Functions:</span>
<span class="cm-variable">square</span> <span class="cm-operator">=</span> <span class="cm-keyword">function</span>(<span class="cm-def">x</span>) {
<span class="cm-keyword">return</span> <span class="cm-variable-2">x</span> <span class="cm-operator">*</span> <span class="cm-variable-2">x</span>;
};
<span class="cm-comment">// Arrays:</span>
<span class="cm-variable">list</span> <span class="cm-operator">=</span> [<span class="cm-number">1</span>, <span class="cm-number">2</span>, <span class="cm-number">3</span>, <span class="cm-number">4</span>, <span class="cm-number">5</span>];
<span class="cm-comment">// Objects:</span>
<span class="cm-variable">math</span> <span class="cm-operator">=</span> {
<span class="cm-property">root</span>: <span class="cm-variable">Math</span>.<span class="cm-property">sqrt</span>,
<span class="cm-property">square</span>: <span class="cm-variable">square</span>,
<span class="cm-property">cube</span>: <span class="cm-keyword">function</span>(<span class="cm-def">x</span>) {
<span class="cm-keyword">return</span> <span class="cm-variable-2">x</span> <span class="cm-operator">*</span> <span class="cm-variable">square</span>(<span class="cm-variable-2">x</span>);
}
};
<span class="cm-comment">// Splats:</span>
<span class="cm-variable">race</span> <span class="cm-operator">=</span> <span class="cm-keyword">function</span>(<span class="cm-def">winner</span>, <span class="cm-meta">...</span><span class="cm-def">runners</span>) {
<span class="cm-keyword">return</span> <span class="cm-variable">print</span>(<span class="cm-variable-2">winner</span>, <span class="cm-variable-2">runners</span>);
};
<span class="cm-keyword">if</span> (<span class="cm-keyword">typeof</span> <span class="cm-variable">elvis</span> <span class="cm-operator">!==</span> <span class="cm-string">"undefined"</span> <span class="cm-operator">&&</span> <span class="cm-variable">elvis</span> <span class="cm-operator">!==</span> <span class="cm-atom">null</span>) {
<span class="cm-comment">// Existence:</span>
<span class="cm-variable">alert</span>(<span class="cm-string">"I knew it!"</span>);
}
<span class="cm-comment">// Array comprehensions:</span>
<span class="cm-variable">cubes</span> <span class="cm-operator">=</span> (<span class="cm-keyword">function</span>() {
<span class="cm-keyword">var</span> <span class="cm-def">i</span>, <span class="cm-def">len</span>, <span class="cm-def">results</span>;
<span class="cm-variable-2">results</span> <span class="cm-operator">=</span> [];
<span class="cm-keyword">for</span> (<span class="cm-variable-2">i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>, <span class="cm-variable-2">len</span> <span class="cm-operator">=</span> <span class="cm-variable">list</span>.<span class="cm-property">length</span>; <span class="cm-variable-2">i</span> <span class="cm-operator"><</span> <span class="cm-variable-2">len</span>; <span class="cm-variable-2">i</span><span class="cm-operator">++</span>) {
<span class="cm-variable">num</span> <span class="cm-operator">=</span> <span class="cm-variable">list</span>[<span class="cm-variable-2">i</span>];
<span class="cm-variable-2">results</span>.<span class="cm-property">push</span>(<span class="cm-variable">math</span>.<span class="cm-property">cube</span>(<span class="cm-variable">num</span>));
}
<span class="cm-keyword">return</span> <span class="cm-variable-2">results</span>;
})();
</pre>
</div>
</div>
<div class="row">
<div class="col text-right">
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="overview" data-run="cubes"><small><svg class="play-button" viewBox="0 0 24 24">
<path d="M2.56-0.01v24.02L21.44 11.98 2.56-0.01z"></path>
</svg>
</small>cubes</button>
</div>
</div>
</aside>
</section>
<section id="coffeescript-2">
<h2>CoffeeScript 2</h2>
<section id="whats-new-in-coffeescript-2">
<h3>What’s New In CoffeeScript 2?</h3>
<p>The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern JavaScript syntax (ES6, or ES2015 and later). A CoffeeScript <code>=></code> becomes a JS <code>=></code>, a CoffeeScript <code>class</code> becomes a JS <code>class</code> and so on. Major new features in CoffeeScript 2 include <a href="#async-functions">async functions</a> and <a href="#jsx">JSX</a>. You can read more in the <a href="announcing-coffeescript-2/">announcement</a>.</p>
<p>There are very few <a href="#breaking-changes">breaking changes from CoffeeScript 1.x to 2</a>; we hope the upgrade process is smooth for most projects.</p>
</section>
<section id="compatibility">
<h3>Compatibility</h3>
<p>Most modern JavaScript features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScript’s output without any further processing required. Here are some notable exceptions:</p>
<ul>
<li><a href="#jsx">JSX</a> always requires transpilation.</li>
<li><a href="https://coffeescript.org/#splats">Splats, a.k.a. object rest/spread syntax, for objects</a> are supported by Node 8.6+.</li>
<li>The <a href="https://github.com/tc39/proposal-regexp-dotall-flag">regular expression <code>s</code> (dotall) flag</a> is supported by Node 9+.</li>
<li><a href="https://github.com/tc39/proposal-async-iteration">Async generator functions</a> are supported by Node 10+.</li>
<li><a href="#modules">Modules</a> are supported by Node 12+ with <code>"type": "module"</code> in your project’s <code>package.json</code>.</li>
</ul>
<p>This list may be incomplete, and excludes versions of Node that support newer features behind flags; please refer to <a href="http://node.green/">node.green</a> for full details. You can <a href="test.html">run the tests in your browser</a> to see what your browser supports. It is your responsibility to ensure that your runtime supports the modern features you use; or that you <a href="#transpilation">transpile</a> your code. When in doubt, transpile.</p>
<p>For compatibility with other JavaScript frameworks and tools, see <a href="#integrations">Integrations</a>.</p>
</section>
</section>
<section id="installation">
<h2>Installation</h2>
<p>The command-line version of <code>coffee</code> is available as a <a href="https://nodejs.org/">Node.js</a> utility, requiring Node 6 or later. The <a href="/v2/browser-compiler-modern/coffeescript.js">core compiler</a> however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see <a href="#try">Try CoffeeScript</a>).</p>
<p>To install, first make sure you have a working copy of the latest stable version of <a href="https://nodejs.org/">Node.js</a>. You can then install CoffeeScript globally with <a href="https://www.npmjs.com/">npm</a>:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --global coffeescript
</code></pre>
</blockquote><p>This will make the <code>coffee</code> and <code>cake</code> commands available globally.</p>
<p>If you are using CoffeeScript in a project, you should install it locally for that project so that the version of CoffeeScript is tracked as one of your project’s dependencies. Within that project’s folder:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --save-dev coffeescript
</code></pre>
</blockquote><p>The <code>coffee</code> and <code>cake</code> commands will first look in the current folder to see if CoffeeScript is installed locally, and use that version if so. This allows different versions of CoffeeScript to be installed globally and locally.</p>
<p>If you plan to use the <code>--transpile</code> option (see <a href="#transpilation">Transpilation</a>) you will need to also install <code>@babel/core</code> either globally or locally, depending on whether you are running a globally or locally installed version of CoffeeScript.</p>
</section>
<section id="usage">
<h2>Usage</h2>
<section id="cli">
<h3>Command Line</h3>
<p>Once installed, you should have access to the <code>coffee</code> command, which can execute scripts, compile <code>.coffee</code> files into <code>.js</code>, and provide an interactive REPL. The <code>coffee</code> command takes the following options:</p>
<table>
<thead>
<tr>
<th>Option</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-c, --compile</code></td>
<td>Compile a <code>.coffee</code> script into a <code>.js</code> JavaScript file of the same name.</td>
</tr>
<tr>
<td><code>-t, --transpile</code></td>
<td>Pipe the CoffeeScript compiler’s output through Babel before saving or running the generated JavaScript. Requires <code>@babel/core</code> to be installed, and options to pass to Babel in a <code>.babelrc</code> file or a <code>package.json</code> with a <code>babel</code> key in the path of the file or folder to be compiled. See <a href="#transpilation">Transpilation</a>.</td>
</tr>
<tr>
<td><code>-m, --map</code></td>
<td>Generate source maps alongside the compiled JavaScript files. Adds <code>sourceMappingURL</code> directives to the JavaScript as well.</td>
</tr>
<tr>
<td><code>-M, --inline-map</code></td>
<td>Just like <code>--map</code>, but include the source map directly in the compiled JavaScript files, rather than in a separate file.</td>
</tr>
<tr>
<td><code>-i, --interactive</code></td>
<td>Launch an interactive CoffeeScript session to try short snippets. Identical to calling <code>coffee</code> with no arguments.</td>
</tr>
<tr>
<td><code>-o, --output [DIR]</code></td>
<td>Write out all compiled JavaScript files into the specified directory. Use in conjunction with <code>--compile</code> or <code>--watch</code>.</td>
</tr>
<tr>
<td><code>-w, --watch</code></td>
<td>Watch files for changes, rerunning the specified command when any file is updated.</td>
</tr>
<tr>
<td><code>-p, --print</code></td>
<td>Instead of writing out the JavaScript as a file, print it directly to <strong>stdout</strong>.</td>
</tr>
<tr>
<td><code>-s, --stdio</code></td>
<td>Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT. Good for use with processes written in other languages. An example:<br><code>cat src/cake.coffee | coffee -sc</code></td>
</tr>
<tr>
<td><code>-l, --literate</code></td>
<td>Parses the code as Literate CoffeeScript. You only need to specify this when passing in code directly over <strong>stdio</strong>, or using some sort of extension-less file name.</td>
</tr>
<tr>
<td><code>-e, --eval</code></td>
<td>Compile and print a little snippet of CoffeeScript directly from the command line. For example:<br><code>coffee -e "console.log num for num in [10..1]"</code></td>
</tr>
<tr>
<td><code>-r, --require [MODULE]</code> </td>
<td><code>require()</code> the given module before starting the REPL or evaluating the code given with the <code>--eval</code> flag.</td>
</tr>
<tr>
<td><code>-b, --bare</code></td>
<td>Compile the JavaScript without the <a href="#lexical-scope">top-level function safety wrapper</a>.</td>
</tr>
<tr>