spade 0.0.8.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.gitmodules +4 -4
- data/README.md +4 -0
- data/bin/spade +1 -1
- data/lib/spade.rb +0 -51
- data/lib/spade/cli.rb +10 -4
- data/lib/spade/version.rb +1 -1
- data/spade.gemspec +4 -21
- metadata +13 -482
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -40
- data/lib/index.js +0 -14
- data/lib/node/loader.js +0 -146
- data/lib/node/sandbox.js +0 -44
- data/lib/spade.js +0 -1130
- data/lib/spade/bundle.rb +0 -171
- data/lib/spade/cli/base.rb +0 -354
- data/lib/spade/cli/owner.rb +0 -45
- data/lib/spade/cli/project_generator.rb +0 -58
- data/lib/spade/compiler.rb +0 -34
- data/lib/spade/console.rb +0 -39
- data/lib/spade/context.rb +0 -116
- data/lib/spade/credentials.rb +0 -36
- data/lib/spade/dependency_installer.rb +0 -103
- data/lib/spade/environment.rb +0 -35
- data/lib/spade/exports.rb +0 -71
- data/lib/spade/installer.rb +0 -40
- data/lib/spade/loader.rb +0 -238
- data/lib/spade/local.rb +0 -46
- data/lib/spade/package.rb +0 -157
- data/lib/spade/reactor.rb +0 -159
- data/lib/spade/remote.rb +0 -99
- data/lib/spade/repository.rb +0 -18
- data/lib/spade/server.rb +0 -66
- data/lib/spade/shell.rb +0 -36
- data/lib/spade/templates/project/LICENSE +0 -19
- data/lib/spade/templates/project/README.md +0 -21
- data/lib/spade/templates/project/lib/main.js +0 -9
- data/lib/spade/templates/project/project.json +0 -31
- data/lib/spade/templates/project/tests/main-test.js +0 -8
- data/package.json +0 -27
- data/packages/coffee-script/.gitignore +0 -8
- data/packages/coffee-script/.npmignore +0 -11
- data/packages/coffee-script/Cakefile +0 -229
- data/packages/coffee-script/LICENSE +0 -22
- data/packages/coffee-script/README +0 -47
- data/packages/coffee-script/Rakefile +0 -78
- data/packages/coffee-script/bin/cake +0 -7
- data/packages/coffee-script/bin/coffee +0 -7
- data/packages/coffee-script/documentation/coffee/aliases.coffee +0 -11
- data/packages/coffee-script/documentation/coffee/array_comprehensions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/block_comment.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/cake_tasks.coffee +0 -9
- data/packages/coffee-script/documentation/coffee/classes.coffee +0 -25
- data/packages/coffee-script/documentation/coffee/comparisons.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/conditionals.coffee +0 -13
- data/packages/coffee-script/documentation/coffee/default_args.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/do.coffee +0 -4
- data/packages/coffee-script/documentation/coffee/embedded.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/existence.coffee +0 -10
- data/packages/coffee-script/documentation/coffee/expressions.coffee +0 -9
- data/packages/coffee-script/documentation/coffee/expressions_assignment.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/expressions_comprehension.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/expressions_try.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/fat_arrow.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/functions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/heredocs.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/heregexes.coffee +0 -11
- data/packages/coffee-script/documentation/coffee/interpolation.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/multiple_return_values.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/object_comprehensions.coffee +0 -4
- data/packages/coffee-script/documentation/coffee/object_extraction.coffee +0 -13
- data/packages/coffee-script/documentation/coffee/objects_and_arrays.coffee +0 -19
- data/packages/coffee-script/documentation/coffee/objects_reserved.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/overview.coffee +0 -28
- data/packages/coffee-script/documentation/coffee/parallel_assignment.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/patterns_and_splats.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/prototypes.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/range_comprehensions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/scope.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/slices.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/soaks.coffee +0 -1
- data/packages/coffee-script/documentation/coffee/splats.coffee +0 -27
- data/packages/coffee-script/documentation/coffee/splices.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/strings.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/switch.coffee +0 -10
- data/packages/coffee-script/documentation/coffee/try.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/while.coffee +0 -10
- data/packages/coffee-script/documentation/css/docs.css +0 -374
- data/packages/coffee-script/documentation/css/idle.css +0 -64
- data/packages/coffee-script/documentation/docs/browser.html +0 -25
- data/packages/coffee-script/documentation/docs/cake.html +0 -43
- data/packages/coffee-script/documentation/docs/coffee-script.html +0 -51
- data/packages/coffee-script/documentation/docs/command.html +0 -161
- data/packages/coffee-script/documentation/docs/docco.css +0 -186
- data/packages/coffee-script/documentation/docs/grammar.html +0 -399
- data/packages/coffee-script/documentation/docs/helpers.html +0 -31
- data/packages/coffee-script/documentation/docs/index.html +0 -3
- data/packages/coffee-script/documentation/docs/lexer.html +0 -490
- data/packages/coffee-script/documentation/docs/nodes.html +0 -1338
- data/packages/coffee-script/documentation/docs/optparse.html +0 -78
- data/packages/coffee-script/documentation/docs/repl.html +0 -24
- data/packages/coffee-script/documentation/docs/rewriter.html +0 -251
- data/packages/coffee-script/documentation/docs/scope.html +0 -54
- data/packages/coffee-script/documentation/docs/underscore.html +0 -295
- data/packages/coffee-script/documentation/images/background.png +0 -0
- data/packages/coffee-script/documentation/images/banding.png +0 -0
- data/packages/coffee-script/documentation/images/button_bg.png +0 -0
- data/packages/coffee-script/documentation/images/button_bg_dark.gif +0 -0
- data/packages/coffee-script/documentation/images/button_bg_green.gif +0 -0
- data/packages/coffee-script/documentation/images/favicon.ico +0 -0
- data/packages/coffee-script/documentation/images/logo.png +0 -0
- data/packages/coffee-script/documentation/images/screenshadow.png +0 -0
- data/packages/coffee-script/documentation/index.html.erb +0 -1607
- data/packages/coffee-script/documentation/js/aliases.js +0 -17
- data/packages/coffee-script/documentation/js/array_comprehensions.js +0 -6
- data/packages/coffee-script/documentation/js/block_comment.js +0 -4
- data/packages/coffee-script/documentation/js/cake_tasks.js +0 -10
- data/packages/coffee-script/documentation/js/classes.js +0 -44
- data/packages/coffee-script/documentation/js/comparisons.js +0 -3
- data/packages/coffee-script/documentation/js/conditionals.js +0 -12
- data/packages/coffee-script/documentation/js/default_args.js +0 -7
- data/packages/coffee-script/documentation/js/do.js +0 -10
- data/packages/coffee-script/documentation/js/embedded.js +0 -4
- data/packages/coffee-script/documentation/js/existence.js +0 -6
- data/packages/coffee-script/documentation/js/expressions.js +0 -15
- data/packages/coffee-script/documentation/js/expressions_assignment.js +0 -2
- data/packages/coffee-script/documentation/js/expressions_comprehension.js +0 -9
- data/packages/coffee-script/documentation/js/expressions_try.js +0 -7
- data/packages/coffee-script/documentation/js/fat_arrow.js +0 -9
- data/packages/coffee-script/documentation/js/functions.js +0 -7
- data/packages/coffee-script/documentation/js/heredocs.js +0 -2
- data/packages/coffee-script/documentation/js/heregexes.js +0 -2
- data/packages/coffee-script/documentation/js/interpolation.js +0 -4
- data/packages/coffee-script/documentation/js/multiple_return_values.js +0 -5
- data/packages/coffee-script/documentation/js/object_comprehensions.js +0 -15
- data/packages/coffee-script/documentation/js/object_extraction.js +0 -10
- data/packages/coffee-script/documentation/js/objects_and_arrays.js +0 -17
- data/packages/coffee-script/documentation/js/objects_reserved.js +0 -4
- data/packages/coffee-script/documentation/js/overview.js +0 -35
- data/packages/coffee-script/documentation/js/parallel_assignment.js +0 -4
- data/packages/coffee-script/documentation/js/patterns_and_splats.js +0 -4
- data/packages/coffee-script/documentation/js/prototypes.js +0 -3
- data/packages/coffee-script/documentation/js/range_comprehensions.js +0 -9
- data/packages/coffee-script/documentation/js/scope.js +0 -8
- data/packages/coffee-script/documentation/js/slices.js +0 -4
- data/packages/coffee-script/documentation/js/soaks.js +0 -2
- data/packages/coffee-script/documentation/js/splats.js +0 -15
- data/packages/coffee-script/documentation/js/splices.js +0 -3
- data/packages/coffee-script/documentation/js/strings.js +0 -2
- data/packages/coffee-script/documentation/js/switch.js +0 -23
- data/packages/coffee-script/documentation/js/try.js +0 -8
- data/packages/coffee-script/documentation/js/while.js +0 -18
- data/packages/coffee-script/documentation/vendor/jquery-1.4.2.js +0 -6240
- data/packages/coffee-script/examples/beautiful_code/binary_search.coffee +0 -16
- data/packages/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +0 -13
- data/packages/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +0 -34
- data/packages/coffee-script/examples/blocks.coffee +0 -54
- data/packages/coffee-script/examples/code.coffee +0 -167
- data/packages/coffee-script/examples/computer_science/README +0 -4
- data/packages/coffee-script/examples/computer_science/binary_search.coffee +0 -25
- data/packages/coffee-script/examples/computer_science/bubble_sort.coffee +0 -11
- data/packages/coffee-script/examples/computer_science/linked_list.coffee +0 -108
- data/packages/coffee-script/examples/computer_science/luhn_algorithm.coffee +0 -36
- data/packages/coffee-script/examples/computer_science/merge_sort.coffee +0 -19
- data/packages/coffee-script/examples/computer_science/selection_sort.coffee +0 -23
- data/packages/coffee-script/examples/poignant.coffee +0 -181
- data/packages/coffee-script/examples/potion.coffee +0 -206
- data/packages/coffee-script/examples/underscore.coffee +0 -682
- data/packages/coffee-script/examples/web_server.coffee +0 -12
- data/packages/coffee-script/extras/EXTRAS +0 -7
- data/packages/coffee-script/extras/coffee-script.js +0 -8
- data/packages/coffee-script/extras/jsl.conf +0 -44
- data/packages/coffee-script/index.html +0 -2515
- data/packages/coffee-script/lib/browser.js +0 -52
- data/packages/coffee-script/lib/cake.js +0 -76
- data/packages/coffee-script/lib/coffee-script.js +0 -82
- data/packages/coffee-script/lib/command.js +0 -263
- data/packages/coffee-script/lib/grammar.js +0 -581
- data/packages/coffee-script/lib/helpers.js +0 -66
- data/packages/coffee-script/lib/index.js +0 -8
- data/packages/coffee-script/lib/lexer.js +0 -633
- data/packages/coffee-script/lib/nodes.js +0 -2165
- data/packages/coffee-script/lib/optparse.js +0 -111
- data/packages/coffee-script/lib/parser.js +0 -649
- data/packages/coffee-script/lib/repl.js +0 -42
- data/packages/coffee-script/lib/rewriter.js +0 -353
- data/packages/coffee-script/lib/scope.js +0 -120
- data/packages/coffee-script/lib/spade-format.js +0 -45
- data/packages/coffee-script/package.json +0 -26
- data/packages/coffee-script/src/browser.coffee +0 -43
- data/packages/coffee-script/src/cake.coffee +0 -69
- data/packages/coffee-script/src/coffee-script.coffee +0 -92
- data/packages/coffee-script/src/command.coffee +0 -214
- data/packages/coffee-script/src/grammar.coffee +0 -590
- data/packages/coffee-script/src/helpers.coffee +0 -56
- data/packages/coffee-script/src/index.coffee +0 -2
- data/packages/coffee-script/src/lexer.coffee +0 -653
- data/packages/coffee-script/src/nodes.coffee +0 -1754
- data/packages/coffee-script/src/optparse.coffee +0 -99
- data/packages/coffee-script/src/repl.coffee +0 -42
- data/packages/coffee-script/src/rewriter.coffee +0 -326
- data/packages/coffee-script/src/scope.coffee +0 -94
- data/packages/coffee-script/test/arguments.coffee +0 -127
- data/packages/coffee-script/test/assignment.coffee +0 -98
- data/packages/coffee-script/test/break.coffee +0 -18
- data/packages/coffee-script/test/comments.coffee +0 -201
- data/packages/coffee-script/test/conditionals.coffee +0 -181
- data/packages/coffee-script/test/exception_handling.coffee +0 -90
- data/packages/coffee-script/test/helpers.coffee +0 -96
- data/packages/coffee-script/test/importing.coffee +0 -18
- data/packages/coffee-script/test/operators.coffee +0 -225
- data/packages/coffee-script/test/ranges_slices_and_splices.coffee +0 -186
- data/packages/coffee-script/test/regular_expressions.coffee +0 -56
- data/packages/coffee-script/test/test.html +0 -123
- data/packages/coffee-script/test/test_chaining.coffee +0 -77
- data/packages/coffee-script/test/test_classes.coffee +0 -372
- data/packages/coffee-script/test/test_compilation.coffee +0 -26
- data/packages/coffee-script/test/test_comprehensions.coffee +0 -318
- data/packages/coffee-script/test/test_existence.coffee +0 -165
- data/packages/coffee-script/test/test_functions.coffee +0 -379
- data/packages/coffee-script/test/test_heredocs.coffee +0 -111
- data/packages/coffee-script/test/test_literals.coffee +0 -270
- data/packages/coffee-script/test/test_option_parser.coffee +0 -27
- data/packages/coffee-script/test/test_pattern_matching.coffee +0 -162
- data/packages/coffee-script/test/test_returns.coffee +0 -63
- data/packages/coffee-script/test/test_splats.coffee +0 -102
- data/packages/coffee-script/test/test_strings.coffee +0 -118
- data/packages/coffee-script/test/test_switch.coffee +0 -103
- data/packages/coffee-script/test/test_while.coffee +0 -71
- data/packages/ivory/LICENSE.txt +0 -1
- data/packages/ivory/README.md +0 -19
- data/packages/ivory/lib/buffer.js +0 -111
- data/packages/ivory/lib/events.js +0 -137
- data/packages/ivory/lib/fs.js +0 -266
- data/packages/ivory/lib/main.js +0 -13
- data/packages/ivory/lib/path.js +0 -158
- data/packages/ivory/lib/ruby/buffer.rb +0 -145
- data/packages/ivory/lib/ruby/constants.rb +0 -585
- data/packages/ivory/lib/ruby/events.rb +0 -32
- data/packages/ivory/lib/ruby/fs.rb +0 -245
- data/packages/ivory/lib/ruby/process.rb +0 -28
- data/packages/ivory/lib/stream.js +0 -115
- data/packages/ivory/lib/util.js +0 -414
- data/packages/ivory/package.json +0 -11
- data/packages/jquery/main.js +0 -7179
- data/packages/jquery/package.json +0 -10
- data/packages/json/lib/main.js +0 -14
- data/packages/json/package.json +0 -8
- data/packages/lproj/README.md +0 -77
- data/packages/lproj/examples/demo-app/en.lproj/localized.strings +0 -2
- data/packages/lproj/examples/demo-app/fr.lproj/localized.strings +0 -3
- data/packages/lproj/examples/demo-app/index.html +0 -8
- data/packages/lproj/examples/demo-app/lib/main.js +0 -7
- data/packages/lproj/examples/demo-app/package.json +0 -9
- data/packages/lproj/lib/main.js +0 -78
- data/packages/lproj/lib/strings-format.js +0 -6
- data/packages/lproj/package.json +0 -9
- data/packages/optparse/README.md +0 -161
- data/packages/optparse/TODO +0 -1
- data/packages/optparse/examples/browser-test.html +0 -75
- data/packages/optparse/examples/nodejs-test.js +0 -90
- data/packages/optparse/lib/optparse.js +0 -309
- data/packages/optparse/package.json +0 -13
- data/packages/optparse/seed.yml +0 -5
- data/packages/text/lib/main.js +0 -8
- data/packages/text/package.json +0 -9
- data/packages/web-file/README.md +0 -7
- data/packages/web-file/lib/errors.js +0 -32
- data/packages/web-file/lib/file-reader.js +0 -10
- data/packages/web-file/lib/file-system.js +0 -234
- data/packages/web-file/lib/file-writer.js +0 -10
- data/packages/web-file/lib/file.js +0 -9
- data/packages/web-file/lib/main.js +0 -34
- data/packages/web-file/lib/platform.js +0 -25
- data/packages/web-file/lib/ruby/file.rb +0 -252
- data/packages/web-file/lib/ruby/file_reader.rb +0 -69
- data/packages/web-file/lib/ruby/file_system.rb +0 -134
- data/packages/web-file/lib/ruby/file_writer.rb +0 -78
- data/packages/web-file/package.json +0 -12
- data/packages/web-typed-array/README.md +0 -7
- data/packages/web-typed-array/lib/array-buffer-view.js +0 -9
- data/packages/web-typed-array/lib/array-buffer.js +0 -7
- data/packages/web-typed-array/lib/main.js +0 -33
- data/packages/web-typed-array/lib/platform.js +0 -20
- data/packages/web-typed-array/lib/ruby/array_buffer.rb +0 -31
- data/packages/web-typed-array/lib/ruby/array_buffer_view.rb +0 -130
- data/packages/web-typed-array/lib/ruby/typed_array.rb +0 -133
- data/packages/web-typed-array/lib/typed-array.js +0 -26
- data/packages/web-typed-array/package.json +0 -9
- data/spec/cli/build_spec.rb +0 -59
- data/spec/cli/install_spec.rb +0 -120
- data/spec/cli/installed_spec.rb +0 -55
- data/spec/cli/list_spec.rb +0 -75
- data/spec/cli/login_spec.rb +0 -76
- data/spec/cli/new_spec.rb +0 -5
- data/spec/cli/owner_spec.rb +0 -115
- data/spec/cli/push_spec.rb +0 -74
- data/spec/cli/uninstall_spec.rb +0 -58
- data/spec/cli/unpack_spec.rb +0 -73
- data/spec/cli/unyank_spec.rb +0 -74
- data/spec/cli/update_spec.rb +0 -8
- data/spec/cli/yank_spec.rb +0 -74
- data/spec/credentials_spec.rb +0 -24
- data/spec/fixtures/coffee-1.0.1.pre.spd +0 -0
- data/spec/fixtures/core-test-0.4.3.spd +0 -0
- data/spec/fixtures/core-test/bin/cot +0 -3
- data/spec/fixtures/core-test/lib/main.js +0 -1
- data/spec/fixtures/core-test/resources/runner.css +0 -0
- data/spec/fixtures/core-test/tests/test.js +0 -1
- data/spec/fixtures/ivory-0.0.1.spd +0 -0
- data/spec/fixtures/jquery-1.4.3.spd +0 -0
- data/spec/fixtures/optparse-1.0.1.spd +0 -0
- data/spec/fixtures/package.json +0 -30
- data/spec/gauntlet_spec.rb +0 -27
- data/spec/javascript/async-test.js +0 -123
- data/spec/javascript/compiler/javascript.js +0 -13
- data/spec/javascript/compiler/ruby.js +0 -14
- data/spec/javascript/loader-test.js +0 -64
- data/spec/javascript/normalize-test.js +0 -73
- data/spec/javascript/packages-test.js +0 -44
- data/spec/javascript/relative-require-test.js +0 -72
- data/spec/javascript/require-test.js +0 -117
- data/spec/javascript/sandbox/compile.js +0 -37
- data/spec/javascript/sandbox/creation.js +0 -44
- data/spec/javascript/sandbox/format.js +0 -79
- data/spec/javascript/sandbox/misc.js +0 -57
- data/spec/javascript/sandbox/preprocessor.js +0 -81
- data/spec/javascript/sandbox/require.js +0 -48
- data/spec/javascript/sandbox/run-command.js +0 -21
- data/spec/javascript/spade/externs.js +0 -14
- data/spec/javascript/spade/load-factory.js +0 -15
- data/spec/javascript/spade/misc.js +0 -23
- data/spec/javascript/spade/ready.js +0 -12
- data/spec/javascript/spade/register.js +0 -13
- data/spec/javascript_spec.rb +0 -7
- data/spec/package_spec.rb +0 -267
- data/spec/spec_helper.rb +0 -30
- data/spec/support/cli.rb +0 -94
- data/spec/support/core_test.rb +0 -59
- data/spec/support/fake.rb +0 -44
- data/spec/support/fake_gem_server.rb +0 -66
- data/spec/support/fake_gemcutter.rb +0 -49
- data/spec/support/matchers.rb +0 -31
- data/spec/support/path.rb +0 -54
- data/test-spade.html +0 -8
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,1607 +0,0 @@
|
|
1
|
-
<%
|
2
|
-
require 'uv'
|
3
|
-
require 'json'
|
4
|
-
@counter = 0
|
5
|
-
def code_for(file, executable=false, show_load=true)
|
6
|
-
@counter += 1
|
7
|
-
return '' unless File.exists?("documentation/js/#{file}.js")
|
8
|
-
cs = File.read("documentation/coffee/#{file}.coffee")
|
9
|
-
js = File.read("documentation/js/#{file}.js")
|
10
|
-
cshtml = Uv.parse(cs, 'xhtml', 'coffeescript', false, 'idle', false)
|
11
|
-
jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false)
|
12
|
-
append = executable == true ? '' : "alert(#{executable});"
|
13
|
-
if executable and executable != true
|
14
|
-
cs.sub!(/(\S)\s*\Z/m, "\\1\n\nalert #{executable}")
|
15
|
-
end
|
16
|
-
run = executable == true ? 'run' : "run: #{executable}"
|
17
|
-
name = "example#{@counter}"
|
18
|
-
script = "<script>window.#{name} = #{cs.to_json}</script>"
|
19
|
-
import = show_load ? "<div class='minibutton load' onclick='javascript: loadConsole(#{name});'>load</div>" : ''
|
20
|
-
button = executable ? "<div class='minibutton ok' onclick='javascript: #{js};#{append}'>#{run}</div>" : ''
|
21
|
-
"<div class='code'>#{cshtml}#{jshtml}#{script}#{import}#{button}<br class='clear' /></div>"
|
22
|
-
end
|
23
|
-
%>
|
24
|
-
|
25
|
-
|
26
|
-
<!DOCTYPE html>
|
27
|
-
<html>
|
28
|
-
<head>
|
29
|
-
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
30
|
-
<title>CoffeeScript</title>
|
31
|
-
<link rel="stylesheet" type="text/css" href="documentation/css/docs.css" />
|
32
|
-
<link rel="stylesheet" type="text/css" href="documentation/css/idle.css" />
|
33
|
-
<link rel="shortcut icon" href="documentation/images/favicon.ico" />
|
34
|
-
</head>
|
35
|
-
<body>
|
36
|
-
|
37
|
-
<div id="fadeout"></div>
|
38
|
-
|
39
|
-
<div id="flybar">
|
40
|
-
<a id="logo" href="#top"> </a>
|
41
|
-
<div class="navigation toc">
|
42
|
-
<div class="button">
|
43
|
-
Table of Contents
|
44
|
-
</div>
|
45
|
-
<div class="contents menu">
|
46
|
-
<a href="#overview">Overview</a>
|
47
|
-
<a href="#installation">Installation and Usage</a>
|
48
|
-
<a href="#language">Language Reference</a>
|
49
|
-
<a href="#literals">Literals: Functions, Objects and Arrays</a>
|
50
|
-
<a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
|
51
|
-
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
|
52
|
-
<a href="#splats">Splats...</a>
|
53
|
-
<a href="#loops">Loops and Comprehensions</a>
|
54
|
-
<a href="#slices">Array Slicing and Splicing</a>
|
55
|
-
<a href="#expressions">Everything is an Expression</a>
|
56
|
-
<a href="#operators">Operators and Aliases</a>
|
57
|
-
<a href="#classes">Classes, Inheritance, and Super</a>
|
58
|
-
<a href="#destructuring">Destructuring Assignment</a>
|
59
|
-
<a href="#fat_arrow">Function Binding</a>
|
60
|
-
<a href="#embedded">Embedded JavaScript</a>
|
61
|
-
<a href="#switch">Switch and Try/Catch</a>
|
62
|
-
<a href="#comparisons">Chained Comparisons</a>
|
63
|
-
<a href="#strings">String Interpolation, Heredocs, and Block Comments</a>
|
64
|
-
<a href="#regexes">Extended Regular Expressions</a>
|
65
|
-
<a href="#cake">Cake, and Cakefiles</a>
|
66
|
-
<a href="#scripts">"text/coffeescript" Script Tags</a>
|
67
|
-
<a href="#resources">Examples and Resources</a>
|
68
|
-
<a href="#change_log">Change Log</a>
|
69
|
-
</div>
|
70
|
-
</div>
|
71
|
-
<div class="navigation try">
|
72
|
-
<div class="button">
|
73
|
-
Try CoffeeScript
|
74
|
-
<div class="repl_bridge"></div>
|
75
|
-
</div>
|
76
|
-
<div class="contents repl_wrapper">
|
77
|
-
<div class="code">
|
78
|
-
<div class="screenshadow tl"></div>
|
79
|
-
<div class="screenshadow tr"></div>
|
80
|
-
<div class="screenshadow bl"></div>
|
81
|
-
<div class="screenshadow br"></div>
|
82
|
-
<div id="repl_source_wrap">
|
83
|
-
<textarea id="repl_source" rows="100">alert "Hello CoffeeScript!"</textarea>
|
84
|
-
</div>
|
85
|
-
<div id="repl_results_wrap"><pre id="repl_results"></pre></div>
|
86
|
-
<div class="minibutton dark run">Run</div>
|
87
|
-
<br class="clear" />
|
88
|
-
</div>
|
89
|
-
</div>
|
90
|
-
</div>
|
91
|
-
<div class="navigation annotated">
|
92
|
-
<div class="button">
|
93
|
-
Annotated Source
|
94
|
-
</div>
|
95
|
-
<div class="contents menu">
|
96
|
-
<a href="documentation/docs/grammar.html">Grammar Rules — src/grammar</a>
|
97
|
-
<a href="documentation/docs/lexer.html">Lexing Tokens — src/lexer</a>
|
98
|
-
<a href="documentation/docs/rewriter.html">The Rewriter — src/rewriter</a>
|
99
|
-
<a href="documentation/docs/nodes.html">The Syntax Tree — src/nodes</a>
|
100
|
-
<a href="documentation/docs/scope.html">Lexical Scope — src/scope</a>
|
101
|
-
<a href="documentation/docs/helpers.html">Helpers & Utility Functions — src/helpers</a>
|
102
|
-
<a href="documentation/docs/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
|
103
|
-
<a href="documentation/docs/cake.html">Cake & Cakefiles — src/cake</a>
|
104
|
-
<a href="documentation/docs/command.html">"coffee" Command-Line Utility — src/command</a>
|
105
|
-
<a href="documentation/docs/optparse.html">Option Parsing — src/optparse</a>
|
106
|
-
<a href="documentation/docs/repl.html">Interactive REPL — src/repl</a>
|
107
|
-
</div>
|
108
|
-
</div>
|
109
|
-
<div id="error" style="display:none;"></div>
|
110
|
-
</div>
|
111
|
-
|
112
|
-
<div class="container">
|
113
|
-
<span class="bookmark" id="top"></span>
|
114
|
-
|
115
|
-
<p>
|
116
|
-
<b>CoffeeScript is a little language that compiles into JavaScript.</b> Underneath
|
117
|
-
all of those embarrassing braces and semicolons, JavaScript has always had
|
118
|
-
a gorgeous object model at its heart. CoffeeScript is an attempt to expose
|
119
|
-
the good parts of JavaScript in a simple way.
|
120
|
-
</p>
|
121
|
-
|
122
|
-
<p>
|
123
|
-
The golden rule of CoffeeScript is: <i>"It's just JavaScript"</i>. The code
|
124
|
-
compiles one-to-one into the equivalent JS, and there is
|
125
|
-
no interpretation at runtime. You can use any existing JavaScript library
|
126
|
-
seamlessly (and vice-versa). The compiled output is readable and pretty-printed,
|
127
|
-
passes through <a href="http://www.javascriptlint.com/">JavaScript Lint</a>
|
128
|
-
without warnings, will work in every JavaScript implementation, and tends
|
129
|
-
to run as fast or faster than the equivalent handwritten JavaScript.
|
130
|
-
</p>
|
131
|
-
|
132
|
-
<p>
|
133
|
-
<b>Latest Version:</b>
|
134
|
-
<a href="http://github.com/jashkenas/coffee-script/tarball/1.0.0">1.0.0</a>
|
135
|
-
</p>
|
136
|
-
|
137
|
-
<h2>
|
138
|
-
<span id="overview" class="bookmark"></span>
|
139
|
-
Overview
|
140
|
-
</h2>
|
141
|
-
|
142
|
-
<p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
|
143
|
-
|
144
|
-
<%= code_for('overview', 'cubes', false) %>
|
145
|
-
|
146
|
-
<h2>
|
147
|
-
<span id="installation" class="bookmark"></span>
|
148
|
-
Installation and Usage
|
149
|
-
</h2>
|
150
|
-
|
151
|
-
<p>
|
152
|
-
The CoffeeScript compiler is itself
|
153
|
-
<a href="documentation/docs/grammar.html">written in CoffeeScript</a>,
|
154
|
-
using the <a href="http://jison.org">Jison parser generator</a>. The
|
155
|
-
command-line version of <tt>coffee</tt> is available as a
|
156
|
-
<a href="http://nodejs.org/">Node.js</a> utility. The
|
157
|
-
<a href="extras/coffee-script.js">core compiler</a> however, does not
|
158
|
-
depend on Node, and can be run in any JavaScript environment, or in the
|
159
|
-
browser (see "Try CoffeeScript", above).
|
160
|
-
</p>
|
161
|
-
|
162
|
-
<p>
|
163
|
-
To install, first make sure you have a working copy of the latest stable version of
|
164
|
-
<a href="http://nodejs.org/">Node.js</a>, and <a href="http://npmjs.org">npm</a>
|
165
|
-
(the Node Package Manager). You can then install CoffeeScript with npm:
|
166
|
-
</p>
|
167
|
-
|
168
|
-
<pre>
|
169
|
-
npm install coffee-script</pre>
|
170
|
-
|
171
|
-
<p>
|
172
|
-
If you'd prefer to install the latest master version of CoffeeScript, you
|
173
|
-
can clone the CoffeeScript
|
174
|
-
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
|
175
|
-
from GitHub, or download
|
176
|
-
<a href="http://github.com/jashkenas/coffee-script/tarball/master">the source</a> directly.
|
177
|
-
To install the CoffeeScript compiler system-wide
|
178
|
-
under <tt>/usr/local</tt>, open the directory and run:
|
179
|
-
</p>
|
180
|
-
|
181
|
-
<pre>
|
182
|
-
sudo bin/cake install</pre>
|
183
|
-
|
184
|
-
<p>
|
185
|
-
If installing on Ubuntu or Debian,
|
186
|
-
<a href="http://opinionated-programmer.com/2010/12/installing-coffeescript-on-debian-or-ubuntu/">be
|
187
|
-
careful not to use the existing out-of-date package</a>. If installing on
|
188
|
-
Windows, your best bet is probably to run Node.js under Cygwin.
|
189
|
-
</p>
|
190
|
-
|
191
|
-
<p>
|
192
|
-
Once installed, you should have access to the <tt>coffee</tt> command,
|
193
|
-
which can execute scripts, compile <tt>.coffee</tt> files into <tt>.js</tt>,
|
194
|
-
and provide an interactive REPL. The <tt>coffee</tt> command takes the
|
195
|
-
following options:
|
196
|
-
</p>
|
197
|
-
|
198
|
-
<table>
|
199
|
-
<tr>
|
200
|
-
<td><code>-c, --compile</code></td>
|
201
|
-
<td>
|
202
|
-
Compile a <tt>.coffee</tt> script into a <tt>.js</tt> JavaScript file
|
203
|
-
of the same name.
|
204
|
-
</td>
|
205
|
-
</tr>
|
206
|
-
<tr>
|
207
|
-
<td width="25%"><code>-i, --interactive</code></td>
|
208
|
-
<td>
|
209
|
-
Launch an interactive CoffeeScript session to try short snippets.
|
210
|
-
More pleasant if wrapped with
|
211
|
-
<a href="http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap.html">rlwrap</a>.
|
212
|
-
</td>
|
213
|
-
</tr>
|
214
|
-
<tr>
|
215
|
-
<td><code>-o, --output [DIR]</code></td>
|
216
|
-
<td>
|
217
|
-
Write out all compiled JavaScript files into the specified directory.
|
218
|
-
Use in conjunction with <tt>--compile</tt> or <tt>--watch</tt>.
|
219
|
-
</td>
|
220
|
-
</tr>
|
221
|
-
<tr>
|
222
|
-
<td><code>-j, --join</code></td>
|
223
|
-
<td>
|
224
|
-
Before compiling, concatenate all scripts together in the order they
|
225
|
-
were passed. Useful for building large projects.
|
226
|
-
</td>
|
227
|
-
</tr>
|
228
|
-
<tr>
|
229
|
-
<td><code>-w, --watch</code></td>
|
230
|
-
<td>
|
231
|
-
Watch the modification times of the coffee-scripts, recompiling as
|
232
|
-
soon as a change occurs.
|
233
|
-
</td>
|
234
|
-
</tr>
|
235
|
-
<tr>
|
236
|
-
<td><code>-p, --print</code></td>
|
237
|
-
<td>
|
238
|
-
Instead of writing out the JavaScript as a file, print it
|
239
|
-
directly to <b>stdout</b>.
|
240
|
-
</td>
|
241
|
-
</tr>
|
242
|
-
<tr>
|
243
|
-
<td><code>-l, --lint</code></td>
|
244
|
-
<td>
|
245
|
-
If the <tt>jsl</tt>
|
246
|
-
(<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
|
247
|
-
command is installed, use it
|
248
|
-
to check the compilation of a CoffeeScript file. (Handy in
|
249
|
-
conjunction with <br /> <tt>--watch</tt>)
|
250
|
-
</td>
|
251
|
-
</tr>
|
252
|
-
<tr>
|
253
|
-
<td><code>-s, --stdio</code></td>
|
254
|
-
<td>
|
255
|
-
Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT.
|
256
|
-
Good for use with processes written in other languages. An example:<br />
|
257
|
-
<tt>cat src/cake.coffee | coffee -sc</tt>
|
258
|
-
</td>
|
259
|
-
</tr>
|
260
|
-
<tr>
|
261
|
-
<td><code>-e, --eval</code></td>
|
262
|
-
<td>
|
263
|
-
Compile and print a little snippet of CoffeeScript directly from the
|
264
|
-
command line. For example:<br /><tt>coffee -e "puts num for num in [10..1]"</tt>
|
265
|
-
</td>
|
266
|
-
</tr>
|
267
|
-
<tr>
|
268
|
-
<td><code>-r, --require</code></td>
|
269
|
-
<td>
|
270
|
-
Load a library before compiling or executing your script. Can be used
|
271
|
-
to hook in to the compiler (to add Growl notifications, for example).
|
272
|
-
</td>
|
273
|
-
</tr>
|
274
|
-
<tr>
|
275
|
-
<td><code>-b, --bare</code></td>
|
276
|
-
<td>
|
277
|
-
Compile the JavaScript without the top-level function safety wrapper.
|
278
|
-
(Used for CoffeeScript as a Node.js module.)
|
279
|
-
</td>
|
280
|
-
</tr>
|
281
|
-
<tr>
|
282
|
-
<td><code>-t, --tokens</code></td>
|
283
|
-
<td>
|
284
|
-
Instead of parsing the CoffeeScript, just lex it, and print out the
|
285
|
-
token stream: <tt>[IDENTIFIER square] [ASSIGN =] [PARAM_START (]</tt> ...
|
286
|
-
</td>
|
287
|
-
</tr>
|
288
|
-
<tr>
|
289
|
-
<td><code>-n, --nodes</code></td>
|
290
|
-
<td>
|
291
|
-
Instead of compiling the CoffeeScript, just lex and parse it, and print
|
292
|
-
out the parse tree:
|
293
|
-
<pre class="no_bar">
|
294
|
-
Expressions
|
295
|
-
Assign
|
296
|
-
Value "square"
|
297
|
-
Code "x"
|
298
|
-
Op *
|
299
|
-
Value "x"
|
300
|
-
Value "x"</pre>
|
301
|
-
</td>
|
302
|
-
</tr>
|
303
|
-
<tr>
|
304
|
-
<td><code>--nodejs</code></td>
|
305
|
-
<td>
|
306
|
-
The <tt>node</tt> executable has some useful options you can set,
|
307
|
-
such as<br /> <tt>--debug</tt> and <tt>--max-stack-size</tt>. Use this
|
308
|
-
flag to forward options directly to Node.js.
|
309
|
-
</td>
|
310
|
-
</tr>
|
311
|
-
</table>
|
312
|
-
|
313
|
-
<p>
|
314
|
-
<b>Examples:</b>
|
315
|
-
</p>
|
316
|
-
|
317
|
-
<ul>
|
318
|
-
<li>
|
319
|
-
Compile a directory tree of <tt>.coffee</tt> files into a parallel
|
320
|
-
tree of <tt>.js</tt>, in <tt>lib</tt>:<br />
|
321
|
-
<tt>coffee -o lib/ -c src/</tt>
|
322
|
-
</li>
|
323
|
-
<li>
|
324
|
-
Watch a file for changes, and recompile it every time the file is saved:<br />
|
325
|
-
<tt>coffee --watch --compile experimental.coffee</tt>
|
326
|
-
</li>
|
327
|
-
<li>
|
328
|
-
Concatenate a list of files into a single script:<br />
|
329
|
-
<tt>coffee -o lib/ --join --compile src/*.coffee</tt>
|
330
|
-
</li>
|
331
|
-
<li>
|
332
|
-
Print out the compiled JS from a one-liner:<br />
|
333
|
-
<tt>coffee -bpe "alert i for i in [0..10]"</tt>
|
334
|
-
</li>
|
335
|
-
<li>
|
336
|
-
Start the CoffeeScript REPL:<br />
|
337
|
-
<tt>coffee</tt>
|
338
|
-
</li>
|
339
|
-
</ul>
|
340
|
-
|
341
|
-
<h2>
|
342
|
-
<span id="language" class="bookmark"></span>
|
343
|
-
Language Reference
|
344
|
-
</h2>
|
345
|
-
|
346
|
-
<p>
|
347
|
-
<i>
|
348
|
-
This reference is structured so that it can be read from top to bottom,
|
349
|
-
if you like. Later sections use ideas and syntax previously introduced.
|
350
|
-
Familiarity with JavaScript is assumed.
|
351
|
-
In all of the following examples, the source CoffeeScript is provided on
|
352
|
-
the left, and the direct compilation into JavaScript is on the right.
|
353
|
-
</i>
|
354
|
-
</p>
|
355
|
-
|
356
|
-
<p>
|
357
|
-
<i>
|
358
|
-
Many of the examples can be run (where it makes sense) by pressing the <b>run</b>
|
359
|
-
button on the right, and can be loaded into the "Try CoffeeScript"
|
360
|
-
console by pressing the <b>load</b> button on the left.
|
361
|
-
</i>
|
362
|
-
<p>
|
363
|
-
First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code.
|
364
|
-
You don't need to use semicolons <tt>;</tt> to terminate expressions,
|
365
|
-
ending the line will do just as well, (although semicolons can still
|
366
|
-
be used to fit multiple expressions onto a single line.)
|
367
|
-
Instead of using curly braces
|
368
|
-
<tt>{ }</tt> to surround blocks of code in <a href="#functions">functions</a>,
|
369
|
-
<a href="#conditionals">if-statements</a>,
|
370
|
-
<a href="#switch">switch</a>, and <a href="#try">try/catch</a>,
|
371
|
-
use indentation.
|
372
|
-
</p>
|
373
|
-
|
374
|
-
<p>
|
375
|
-
You don't need to use parentheses to invoke a function if you're passing
|
376
|
-
arguments. The implicit call wraps forward to the end of the line or block expression.<br />
|
377
|
-
<tt>console.log sys.inspect object</tt> → <tt>console.log(sys.inspect(object));</tt>
|
378
|
-
</p>
|
379
|
-
|
380
|
-
<p>
|
381
|
-
<span id="literals" class="bookmark"></span>
|
382
|
-
<b class="header">Functions</b>
|
383
|
-
Functions are defined by an optional list of parameters in parentheses,
|
384
|
-
an arrow, and the function body. The empty function looks like this:
|
385
|
-
<tt>-></tt>
|
386
|
-
</p>
|
387
|
-
<%= code_for('functions', 'cube(5)') %>
|
388
|
-
<p>
|
389
|
-
Functions may also have default values for arguments. Override the default
|
390
|
-
value by passing a non-null argument.
|
391
|
-
</p>
|
392
|
-
<%= code_for('default_args', 'fill("cup")') %>
|
393
|
-
|
394
|
-
<p>
|
395
|
-
<span id="objects_and_arrays" class="bookmark"></span>
|
396
|
-
<b class="header">Objects and Arrays</b>
|
397
|
-
The CoffeeScript literals for objects and arrays look very similar to
|
398
|
-
their JavaScript cousins. When each property is listed on its own line,
|
399
|
-
the commas are optional. Objects may be created using indentation instead
|
400
|
-
of explicit braces, similar to <a href="http://yaml.org">YAML</a>.
|
401
|
-
</p>
|
402
|
-
<%= code_for('objects_and_arrays', 'song.join(" ... ")') %>
|
403
|
-
<p>
|
404
|
-
In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
|
405
|
-
of an object, without quoting them as strings. CoffeeScript notices reserved words
|
406
|
-
used as keys in objects and quotes them for you, so you don't have to worry
|
407
|
-
about it (say, when using jQuery).
|
408
|
-
</p>
|
409
|
-
<%= code_for('objects_reserved') %>
|
410
|
-
|
411
|
-
<p>
|
412
|
-
<span id="lexical_scope" class="bookmark"></span>
|
413
|
-
<b class="header">Lexical Scoping and Variable Safety</b>
|
414
|
-
The CoffeeScript compiler takes care to make sure that all of your variables
|
415
|
-
are properly declared within lexical scope — you never need to write
|
416
|
-
<tt>var</tt> yourself.
|
417
|
-
</p>
|
418
|
-
<%= code_for('scope', 'inner') %>
|
419
|
-
<p>
|
420
|
-
Notice how all of the variable declarations have been pushed up to
|
421
|
-
the top of the closest scope, the first time they appear.
|
422
|
-
<b>outer</b> is not redeclared within the inner function, because it's
|
423
|
-
already in scope; <b>inner</b> within the function, on the other hand,
|
424
|
-
should not be able to change the value of the external variable of the same name, and
|
425
|
-
therefore has a declaration of its own.
|
426
|
-
</p>
|
427
|
-
<p>
|
428
|
-
This behavior is effectively identical to Ruby's scope for local variables.
|
429
|
-
Because you don't have direct access to the <tt>var</tt> keyword,
|
430
|
-
it's impossible to shadow an outer variable on purpose, you may only refer
|
431
|
-
to it. So be careful that you're not reusing the name of an external
|
432
|
-
variable accidentally, if you're writing a deeply nested function.
|
433
|
-
</p>
|
434
|
-
<p>
|
435
|
-
Although suppressed within this documentation for clarity, all
|
436
|
-
CoffeeScript output is wrapped in an anonymous function:
|
437
|
-
<tt>(function(){ ... })();</tt> This safety wrapper, combined with the
|
438
|
-
automatic generation of the <tt>var</tt> keyword, make it exceedingly difficult
|
439
|
-
to pollute the global namespace by accident.
|
440
|
-
</p>
|
441
|
-
<p>
|
442
|
-
If you'd like to create top-level variables for other scripts to use,
|
443
|
-
attach them as properties on <b>window</b>, or on the <b>exports</b>
|
444
|
-
object in CommonJS. The <b>existential operator</b> (covered below), gives you a
|
445
|
-
reliable way to figure out where to add them, if you're targeting both
|
446
|
-
CommonJS and the browser: <tt>exports ? this</tt>
|
447
|
-
</p>
|
448
|
-
|
449
|
-
<p>
|
450
|
-
<span id="conditionals" class="bookmark"></span>
|
451
|
-
<b class="header">If, Else, Unless, and Conditional Assignment</b>
|
452
|
-
<b>If/else</b> statements can be written without the use of parentheses and
|
453
|
-
curly brackets. As with functions and other block expressions,
|
454
|
-
multi-line conditionals are delimited by indentation. There's also a handy
|
455
|
-
postfix form, with the <tt>if</tt> or <tt>unless</tt> at the end.
|
456
|
-
</p>
|
457
|
-
<p>
|
458
|
-
CoffeeScript can compile <b>if</b> statements into JavaScript expressions,
|
459
|
-
using the ternary operator when possible, and closure wrapping otherwise. There
|
460
|
-
is no explicit ternary statement in CoffeeScript — you simply use
|
461
|
-
a regular <b>if</b> statement on a single line.
|
462
|
-
</p>
|
463
|
-
<%= code_for('conditionals') %>
|
464
|
-
|
465
|
-
<p>
|
466
|
-
<span id="splats" class="bookmark"></span>
|
467
|
-
<b class="header">Splats...</b>
|
468
|
-
The JavaScript <b>arguments object</b> is a useful way to work with
|
469
|
-
functions that accept variable numbers of arguments. CoffeeScript provides
|
470
|
-
splats <tt>...</tt>, both for function definition as well as invocation,
|
471
|
-
making variable numbers of arguments a little bit more palatable.
|
472
|
-
</p>
|
473
|
-
<%= code_for('splats', true) %>
|
474
|
-
|
475
|
-
<p>
|
476
|
-
<span id="loops" class="bookmark"></span>
|
477
|
-
<b class="header">Loops and Comprehensions</b>
|
478
|
-
Most of the loops you'll write in CoffeeScript will be <b>comprehensions</b>
|
479
|
-
over arrays, objects, and ranges. Comprehensions replace (and compile into)
|
480
|
-
<b>for</b> loops, with optional guard clauses and the value of the current array index.
|
481
|
-
Unlike for loops, array comprehensions are expressions, and can be returned
|
482
|
-
and assigned. They should be able to handle most places where you otherwise
|
483
|
-
would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>.
|
484
|
-
</p>
|
485
|
-
<%= code_for('array_comprehensions') %>
|
486
|
-
<p>
|
487
|
-
If you know the start and end of your loop, or would like to step through
|
488
|
-
in fixed-size increments, you can use a range to specify the start and
|
489
|
-
end of your comprehension.
|
490
|
-
</p>
|
491
|
-
<%= code_for('range_comprehensions', 'countdown') %>
|
492
|
-
<p>
|
493
|
-
Note how because we are assigning the value of the comprehensions to a
|
494
|
-
variable in the example above, CoffeeScript is collecting the result of
|
495
|
-
each iteration into an array. Sometimes functions end with loops that are
|
496
|
-
intended to run only for their side-effects. Be careful that you're not
|
497
|
-
accidentally returning the results of the comprehension in these cases,
|
498
|
-
by adding a meaningful return value, like <tt>true</tt>, or <tt>null</tt>,
|
499
|
-
to the bottom of your function.
|
500
|
-
</p>
|
501
|
-
<p>
|
502
|
-
To step through a range comprehension in fixed-size chunks,
|
503
|
-
use <tt>by</tt>, for example:<br />
|
504
|
-
<tt>evens = (x for x in [0..10] by 2)</tt>
|
505
|
-
</p>
|
506
|
-
<p>
|
507
|
-
Comprehensions can also be used to iterate over the keys and values in
|
508
|
-
an object. Use <tt>of</tt> to signal comprehension over the properties of
|
509
|
-
an object instead of the values in an array.
|
510
|
-
</p>
|
511
|
-
<%= code_for('object_comprehensions', 'ages.join(", ")') %>
|
512
|
-
<p>
|
513
|
-
If you would like to iterate over just the keys that are defined on the
|
514
|
-
object itself, by adding a <tt>hasOwnProperty</tt>
|
515
|
-
check to avoid properties that may be interited from the prototype, use<br />
|
516
|
-
<tt>for own key, value of object</tt>
|
517
|
-
</p>
|
518
|
-
<p>
|
519
|
-
The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
|
520
|
-
main difference from JavaScript is that the <b>while</b> loop can be used
|
521
|
-
as an expression, returning an array containing the result of each iteration
|
522
|
-
through the loop.
|
523
|
-
</p>
|
524
|
-
<%= code_for('while', 'lyrics.join("\n")') %>
|
525
|
-
<p>
|
526
|
-
For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
|
527
|
-
and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
|
528
|
-
</p>
|
529
|
-
<p>
|
530
|
-
When using a JavaScript loop to generate functions, it's common to insert
|
531
|
-
a closure wrapper in order to ensure that loop variables are closed over,
|
532
|
-
and all the generated functions don't just share the final values. CoffeeScript
|
533
|
-
provides the <tt>do</tt> keyword, which immediately invokes a passed function,
|
534
|
-
forwarding any arguments.
|
535
|
-
</p>
|
536
|
-
<%= code_for('do') %>
|
537
|
-
|
538
|
-
<p>
|
539
|
-
<span id="slices" class="bookmark"></span>
|
540
|
-
<b class="header">Array Slicing and Splicing with Ranges</b>
|
541
|
-
Ranges can also be used to extract slices of arrays.
|
542
|
-
With two dots (<tt>3..6</tt>), the range is inclusive (<tt>3, 4, 5, 6</tt>);
|
543
|
-
with three docs (<tt>3...6</tt>), the range excludes the end (<tt>3, 4, 5</tt>).
|
544
|
-
</p>
|
545
|
-
<%= code_for('slices', 'middle') %>
|
546
|
-
<p>
|
547
|
-
The same syntax can be used with assignment to replace a segment of an array
|
548
|
-
with new values, splicing it.
|
549
|
-
</p>
|
550
|
-
<%= code_for('splices', 'numbers') %>
|
551
|
-
<p>
|
552
|
-
Note that JavaScript strings are immutable, and can't be spliced.
|
553
|
-
</p>
|
554
|
-
<p>
|
555
|
-
<span id="expressions" class="bookmark"></span>
|
556
|
-
<b class="header">Everything is an Expression (at least, as much as possible)</b>
|
557
|
-
You might have noticed how even though we don't add return statements
|
558
|
-
to CoffeeScript functions, they nonetheless return their final value.
|
559
|
-
The CoffeeScript compiler tries to make sure that all statements in the
|
560
|
-
language can be used as expressions. Watch how the <tt>return</tt> gets
|
561
|
-
pushed down into each possible branch of execution, in the function
|
562
|
-
below.
|
563
|
-
</p>
|
564
|
-
<%= code_for('expressions', 'eldest') %>
|
565
|
-
<p>
|
566
|
-
Even though functions will always return their final value, it's both possible
|
567
|
-
and encouraged to return early from a function body writing out the explicit
|
568
|
-
return (<tt>return value</tt>), when you know that you're done.
|
569
|
-
</p>
|
570
|
-
<p>
|
571
|
-
Because variable declarations occur at the top of scope, assignment can
|
572
|
-
be used within expressions, even for variables that haven't been seen before:
|
573
|
-
</p>
|
574
|
-
<%= code_for('expressions_assignment', 'six') %>
|
575
|
-
<p>
|
576
|
-
Things that would otherwise be statements in JavaScript, when used
|
577
|
-
as part of an expression in CoffeeScript, are converted into expressions
|
578
|
-
by wrapping them in a closure. This lets you do useful things, like assign
|
579
|
-
the result of a comprehension to a variable:
|
580
|
-
</p>
|
581
|
-
<%= code_for('expressions_comprehension', 'globals') %>
|
582
|
-
<p>
|
583
|
-
As well as silly things, like passing a <b>try/catch</b> statement directly
|
584
|
-
into a function call:
|
585
|
-
</p>
|
586
|
-
<%= code_for('expressions_try', true) %>
|
587
|
-
<p>
|
588
|
-
There are a handful of statements in JavaScript that can't be meaningfully
|
589
|
-
converted into expressions, namely <tt>break</tt>, <tt>continue</tt>,
|
590
|
-
and <tt>return</tt>. If you make use of them within a block of code,
|
591
|
-
CoffeeScript won't try to perform the conversion.
|
592
|
-
</p>
|
593
|
-
|
594
|
-
<p>
|
595
|
-
<span id="operators" class="bookmark"></span>
|
596
|
-
<b class="header">Operators and Aliases</b>
|
597
|
-
Because the <tt>==</tt> operator frequently causes undesirable coercion,
|
598
|
-
is intransitive, and has a different meaning than in other languages,
|
599
|
-
CoffeeScript compiles <tt>==</tt> into <tt>===</tt>, and <tt>!=</tt> into
|
600
|
-
<tt>!==</tt>.
|
601
|
-
In addition, <tt>is</tt> compiles into <tt>===</tt>,
|
602
|
-
and <tt>isnt</tt> into <tt>!==</tt>.
|
603
|
-
</p>
|
604
|
-
<p>
|
605
|
-
You can use <tt>not</tt> as an alias for <tt>!</tt>.
|
606
|
-
</p>
|
607
|
-
<p>
|
608
|
-
For logic, <tt>and</tt> compiles to <tt>&&</tt>, and <tt>or</tt>
|
609
|
-
into <tt>||</tt>.
|
610
|
-
</p>
|
611
|
-
<p>
|
612
|
-
Instead of a newline or semicolon, <tt>then</tt> can be used to separate
|
613
|
-
conditions from expressions, in <b>while</b>,
|
614
|
-
<b>if</b>/<b>else</b>, and <b>switch</b>/<b>when</b> statements.
|
615
|
-
</p>
|
616
|
-
<p>
|
617
|
-
As in <a href="http://yaml.org/">YAML</a>, <tt>on</tt> and <tt>yes</tt>
|
618
|
-
are the same as boolean <tt>true</tt>, while <tt>off</tt> and <tt>no</tt> are boolean <tt>false</tt>.
|
619
|
-
</p>
|
620
|
-
<p>
|
621
|
-
For single-line statements, <tt>unless</tt> can be used as the inverse of <tt>if</tt>.
|
622
|
-
</p>
|
623
|
-
<p>
|
624
|
-
As a shortcut for <tt>this.property</tt>, you can use <tt>@property</tt>.
|
625
|
-
</p>
|
626
|
-
<p>
|
627
|
-
You can use <tt>in</tt> to test for array presence, and <tt>of</tt> to
|
628
|
-
test for JavaScript object-key presence.
|
629
|
-
</p>
|
630
|
-
|
631
|
-
<p>
|
632
|
-
All together now:
|
633
|
-
</p>
|
634
|
-
|
635
|
-
<table class="definitions">
|
636
|
-
<tr><th>CoffeeScript</th><th>JavaScript</th></tr>
|
637
|
-
<tr><td><tt>is</tt></td><td><tt>===</tt></td></tr>
|
638
|
-
<tr><td><tt>isnt</tt></td><td><tt>!==</tt></td></tr>
|
639
|
-
<tr><td><tt>not</tt></td><td><tt>!</tt></td></tr>
|
640
|
-
<tr><td><tt>and</tt></td><td><tt>&&</tt></td></tr>
|
641
|
-
<tr><td><tt>or</tt></td><td><tt>||</tt></td></tr>
|
642
|
-
<tr><td><tt>true, yes, on</tt></td><td><tt>true</tt></td></tr>
|
643
|
-
<tr><td><tt>false, no, off</tt></td><td><tt>false</tt></td></tr>
|
644
|
-
<tr><td><tt>@, this</tt></td><td><tt>this</tt></td></tr>
|
645
|
-
<tr><td><tt>of</tt></td><td><tt>in</tt></td></tr>
|
646
|
-
<tr><td><tt>in</tt></td><td><i><small>no JS equivalent</small></i></td></tr>
|
647
|
-
</table>
|
648
|
-
|
649
|
-
<%= code_for('aliases') %>
|
650
|
-
|
651
|
-
<p>
|
652
|
-
<b class="header">The Existential Operator</b>
|
653
|
-
It's a little difficult to check for the existence of a variable in
|
654
|
-
JavaScript. <tt>if (variable) ...</tt> comes close, but fails for zero,
|
655
|
-
the empty string, and false. CoffeeScript's existential operator <tt>?</tt> returns true unless
|
656
|
-
a variable is <b>null</b> or <b>undefined</b>, which makes it analogous
|
657
|
-
to Ruby's <tt>nil?</tt>
|
658
|
-
</p>
|
659
|
-
<p>
|
660
|
-
It can also be used for safer conditional assignment than <tt>||=</tt>
|
661
|
-
provides, for cases where you may be handling numbers or strings.
|
662
|
-
</p>
|
663
|
-
<%= code_for('existence', 'footprints') %>
|
664
|
-
<p>
|
665
|
-
The accessor variant of the existential operator <tt>?.</tt> can be used to soak
|
666
|
-
up null references in a chain of properties. Use it instead
|
667
|
-
of the dot accessor <tt>.</tt> in cases where the base value may be <b>null</b>
|
668
|
-
or <b>undefined</b>. If all of the properties exist then you'll get the expected
|
669
|
-
result, if the chain is broken, <b>undefined</b> is returned instead of
|
670
|
-
the <b>TypeError</b> that would be raised otherwise.
|
671
|
-
</p>
|
672
|
-
<%= code_for('soaks') %>
|
673
|
-
<p>
|
674
|
-
Soaking up nulls is similar to Ruby's
|
675
|
-
<a href="http://andand.rubyforge.org/">andand gem</a>, and to the
|
676
|
-
<a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">safe navigation operator</a>
|
677
|
-
in Groovy.
|
678
|
-
</p>
|
679
|
-
|
680
|
-
<p>
|
681
|
-
<span id="classes" class="bookmark"></span>
|
682
|
-
<b class="header">Classes, Inheritance, and Super</b>
|
683
|
-
JavaScript's prototypal inheritance has always been a bit of a
|
684
|
-
brain-bender, with a whole family tree of libraries that provide a cleaner
|
685
|
-
syntax for classical inheritance on top of JavaScript's prototypes:
|
686
|
-
<a href="http://code.google.com/p/base2/">Base2</a>,
|
687
|
-
<a href="http://prototypejs.org/">Prototype.js</a>,
|
688
|
-
<a href="http://jsclass.jcoglan.com/">JS.Class</a>, etc.
|
689
|
-
The libraries provide syntactic sugar, but the built-in inheritance would
|
690
|
-
be completely usable if it weren't for a couple of small exceptions:
|
691
|
-
it's awkward to call <b>super</b> (the prototype object's
|
692
|
-
implementation of the current function), and it's awkward to correctly
|
693
|
-
set the prototype chain.
|
694
|
-
</p>
|
695
|
-
<p>
|
696
|
-
Instead of repetitively attaching functions to a prototype, CoffeeScript
|
697
|
-
provides a basic <tt>class</tt> structure that allows you to name your class,
|
698
|
-
set the superclass, assign prototypal properties, and define the constructor,
|
699
|
-
in a single assignable expression.
|
700
|
-
</p>
|
701
|
-
<p>
|
702
|
-
Constructor functions are named, to better support reflection. In the
|
703
|
-
example below for the first class, <tt>this.constructor.name is "Animal"</tt>.
|
704
|
-
</p>
|
705
|
-
<%= code_for('classes', true) %>
|
706
|
-
<p>
|
707
|
-
If structuring your prototypes classically isn't your cup of tea, CoffeeScript
|
708
|
-
provides a couple of lower-level conveniences. The <tt>extends</tt> operator
|
709
|
-
helps with proper prototype setup, <tt>::</tt> gives you
|
710
|
-
quick access to an object's prototype, and <tt>super()</tt>
|
711
|
-
is converted into a call against the immediate ancestor's method of the same name.
|
712
|
-
</p>
|
713
|
-
<%= code_for('prototypes', '"one_two".dasherize()') %>
|
714
|
-
<p>
|
715
|
-
Finally class definitions are blocks of executable code, which make for interesting
|
716
|
-
metaprogramming possibilities. Because in the context of a class definition,
|
717
|
-
<tt>this</tt> is the class object itself (the constructor function), you
|
718
|
-
can assign static properties by using <br /><tt>@property: value</tt>, and call
|
719
|
-
functions defined in parent classes: <tt>@attr 'title', type: 'text'</tt>
|
720
|
-
</p>
|
721
|
-
|
722
|
-
<p>
|
723
|
-
<span id="destructuring" class="bookmark"></span>
|
724
|
-
<b class="header">Destructuring Assignment</b>
|
725
|
-
To make extracting values from complex arrays and objects more convenient,
|
726
|
-
CoffeeScript implements ECMAScript Harmony's proposed
|
727
|
-
<a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">destructuring assignment</a>
|
728
|
-
syntax. When you assign an array or object literal to a value, CoffeeScript
|
729
|
-
breaks up and matches both sides against each other, assigning the values
|
730
|
-
on the right to the variables on the left. In the simplest case, it can be
|
731
|
-
used for parallel assignment:
|
732
|
-
</p>
|
733
|
-
<%= code_for('parallel_assignment', 'theBait') %>
|
734
|
-
<p>
|
735
|
-
But it's also helpful for dealing with functions that return multiple
|
736
|
-
values.
|
737
|
-
</p>
|
738
|
-
<%= code_for('multiple_return_values', 'forecast') %>
|
739
|
-
<p>
|
740
|
-
Destructuring assignment can be used with any depth of array and object nesting,
|
741
|
-
to help pull out deeply nested properties.
|
742
|
-
</p>
|
743
|
-
<%= code_for('object_extraction', 'name + " — " + street') %>
|
744
|
-
<p>
|
745
|
-
Destructuring assignment can even be combined with splats.
|
746
|
-
</p>
|
747
|
-
<%= code_for('patterns_and_splats', 'contents.join("")') %>
|
748
|
-
|
749
|
-
<p>
|
750
|
-
<span id="fat_arrow" class="bookmark"></span>
|
751
|
-
<b class="header">Function binding</b>
|
752
|
-
In JavaScript, the <tt>this</tt> keyword is dynamically scoped to mean the
|
753
|
-
object that the current function is attached to. If you pass a function as
|
754
|
-
as callback, or attach it to a different object, the original value of <tt>this</tt>
|
755
|
-
will be lost. If you're not familiar with this behavior,
|
756
|
-
<a href="http://www.digital-web.com/articles/scope_in_javascript/">this Digital Web article</a>
|
757
|
-
gives a good overview of the quirks.
|
758
|
-
</p>
|
759
|
-
<p>
|
760
|
-
The fat arrow <tt>=></tt> can be used to both define a function, and to bind
|
761
|
-
it to the current value of <tt>this</tt>, right on the spot. This is helpful
|
762
|
-
when using callback-based libraries like Prototype or jQuery, for creating
|
763
|
-
iterator functions to pass to <tt>each</tt>, or event-handler functions
|
764
|
-
to use with <tt>bind</tt>. Functions created with the fat arrow are able to access
|
765
|
-
properties of the <tt>this</tt> where they're defined.
|
766
|
-
</p>
|
767
|
-
<%= code_for('fat_arrow') %>
|
768
|
-
<p>
|
769
|
-
If we had used <tt>-></tt> in the callback above, <tt>@customer</tt> would
|
770
|
-
have referred to the undefined "customer" property of the DOM element,
|
771
|
-
and trying to call <tt>purchase()</tt> on it would have raised an exception.
|
772
|
-
</p>
|
773
|
-
|
774
|
-
<p>
|
775
|
-
<span id="embedded" class="bookmark"></span>
|
776
|
-
<b class="header">Embedded JavaScript</b>
|
777
|
-
Hopefully, you'll never need to use it, but if you ever need to intersperse
|
778
|
-
snippets of JavaScript within your CoffeeScript, you can
|
779
|
-
use backticks to pass it straight through.
|
780
|
-
</p>
|
781
|
-
<%= code_for('embedded', 'hi()') %>
|
782
|
-
|
783
|
-
<p>
|
784
|
-
<span id="switch" class="bookmark"></span>
|
785
|
-
<b class="header">Switch/When/Else</b>
|
786
|
-
<b>Switch</b> statements in JavaScript are a bit awkward. You need to
|
787
|
-
remember to <b>break</b> at the end of every <b>case</b> statement to
|
788
|
-
avoid accidentally falling through to the default case.
|
789
|
-
CoffeeScript prevents accidental fall-through, and can convert the <tt>switch</tt>
|
790
|
-
into a returnable, assignable expression. The format is: <tt>switch</tt> condition,
|
791
|
-
<tt>when</tt> clauses, <tt>else</tt> the default case.
|
792
|
-
</p>
|
793
|
-
<p>
|
794
|
-
As in Ruby, <b>switch</b> statements in CoffeeScript can take multiple
|
795
|
-
values for each <b>when</b> clause. If any of the values match, the clause
|
796
|
-
runs.
|
797
|
-
</p>
|
798
|
-
<%= code_for('switch') %>
|
799
|
-
|
800
|
-
<p>
|
801
|
-
<span id="try" class="bookmark"></span>
|
802
|
-
<b class="header">Try/Catch/Finally</b>
|
803
|
-
Try/catch statements are just about the same as JavaScript (although
|
804
|
-
they work as expressions).
|
805
|
-
</p>
|
806
|
-
<%= code_for('try') %>
|
807
|
-
|
808
|
-
<p>
|
809
|
-
<span id="comparisons" class="bookmark"></span>
|
810
|
-
<b class="header">Chained Comparisons</b>
|
811
|
-
CoffeeScript borrows
|
812
|
-
<a href="http://docs.python.org/reference/expressions.html#notin">chained comparisons</a>
|
813
|
-
from Python — making it easy to test if a value falls within a
|
814
|
-
certain range.
|
815
|
-
</p>
|
816
|
-
<%= code_for('comparisons', 'healthy') %>
|
817
|
-
|
818
|
-
<p>
|
819
|
-
<span id="strings" class="bookmark"></span>
|
820
|
-
<b class="header">String Interpolation, Heredocs, and Block Comments</b>
|
821
|
-
Ruby-style string interpolation is included in CoffeeScript. Double-quoted
|
822
|
-
strings allow for interpolated values, using <tt>#{ ... }</tt>,
|
823
|
-
and single-quoted strings are literal.
|
824
|
-
</p>
|
825
|
-
<%= code_for('interpolation', 'sentence') %>
|
826
|
-
<p>
|
827
|
-
Multiline strings are allowed in CoffeeScript.
|
828
|
-
</p>
|
829
|
-
<%= code_for('strings', 'mobyDick') %>
|
830
|
-
<p>
|
831
|
-
Heredocs can be used to hold formatted or indentation-sensitive text
|
832
|
-
(or, if you just don't feel like escaping quotes and apostrophes). The
|
833
|
-
indentation level that begins the heredoc is maintained throughout, so
|
834
|
-
you can keep it all aligned with the body of your code.
|
835
|
-
</p>
|
836
|
-
<%= code_for('heredocs') %>
|
837
|
-
<p>
|
838
|
-
Double-quoted heredocs, like double-quoted strings, allow interpolation.
|
839
|
-
</p>
|
840
|
-
<p>
|
841
|
-
Sometimes you'd like to pass a block comment through to the generated
|
842
|
-
JavaScript. For example, when you need to embed a licensing header at
|
843
|
-
the top of a file. Block comments, which mirror the synax for heredocs,
|
844
|
-
are preserved in the generated code.
|
845
|
-
</p>
|
846
|
-
<%= code_for('block_comment') %>
|
847
|
-
|
848
|
-
<p>
|
849
|
-
<span id="regexes" class="bookmark"></span>
|
850
|
-
<b class="header">Extended Regular Expressions</b>
|
851
|
-
Similar to "heredocs" and "herecomments", CoffeeScript supports "heregexes" —
|
852
|
-
extended regular expressions that ignore internal whitespace and can contain
|
853
|
-
comments, after Perl's <tt>/x</tt> modifier, but delimited by <tt>///</tt>.
|
854
|
-
They go a long way towards making complex regular expressions readable.
|
855
|
-
To quote from the CoffeeScript source:
|
856
|
-
</p>
|
857
|
-
<%= code_for('heregexes') %>
|
858
|
-
|
859
|
-
|
860
|
-
<h2>
|
861
|
-
<span id="cake" class="bookmark"></span>
|
862
|
-
Cake, and Cakefiles
|
863
|
-
</h2>
|
864
|
-
|
865
|
-
<p>
|
866
|
-
CoffeeScript includes a simple build system similar to
|
867
|
-
<a href="http://www.gnu.org/software/make/">Make</a> and
|
868
|
-
<a href="http://rake.rubyforge.org/">Rake</a>. Naturally,
|
869
|
-
it's called Cake, and is used for the build and test tasks for the CoffeeScript
|
870
|
-
language itself. Tasks are defined in a file named <tt>Cakefile</tt>, and
|
871
|
-
can be invoked by running <tt>cake taskname</tt> from within the directory.
|
872
|
-
To print a list of all the tasks and options, just run <tt>cake</tt>.
|
873
|
-
</p>
|
874
|
-
|
875
|
-
<p>
|
876
|
-
Task definitions are written in CoffeeScript, so you can put arbitrary code
|
877
|
-
in your Cakefile. Define a task with a name, a long description, and the
|
878
|
-
function to invoke when the task is run. If your task takes a command-line
|
879
|
-
option, you can define the option with short and long flags, and it will
|
880
|
-
be made available in the <tt>options</tt> object. Here's a task that uses
|
881
|
-
the Node.js API to rebuild CoffeeScript's parser:
|
882
|
-
</p>
|
883
|
-
<%= code_for('cake_tasks') %>
|
884
|
-
<p>
|
885
|
-
If you need to invoke one task before another — for example, running
|
886
|
-
<tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function:
|
887
|
-
<tt>invoke 'build'</tt>
|
888
|
-
</p>
|
889
|
-
|
890
|
-
<h2>
|
891
|
-
<span id="scripts" class="bookmark"></span>
|
892
|
-
"text/coffeescript" Script Tags
|
893
|
-
</h2>
|
894
|
-
|
895
|
-
<p>
|
896
|
-
While it's not recommended for serious use, CoffeeScripts may be included
|
897
|
-
directly within the browser using <tt><script type="text/coffeescript"></tt>
|
898
|
-
tags. The source includes a compressed and minified version of the compiler
|
899
|
-
(<a href="extras/coffee-script.js">Download current version here, 39k when gzipped</a>)
|
900
|
-
as <tt>extras/coffee-script.js</tt>. Include this file on a page with
|
901
|
-
inline CoffeeScript tags, and it will compile and evaluate them in order.
|
902
|
-
</p>
|
903
|
-
|
904
|
-
<p>
|
905
|
-
In fact, the little bit of glue script that runs "Try CoffeeScript" above,
|
906
|
-
as well as jQuery for the menu, is implemented in just this way.
|
907
|
-
View source and look at the bottom of the page to see the example.
|
908
|
-
Including the script also gives you access to <tt>CoffeeScript.compile()</tt>
|
909
|
-
so you can pop open Firebug and try compiling some strings.
|
910
|
-
</p>
|
911
|
-
|
912
|
-
<p>
|
913
|
-
The usual caveats about CoffeeScript apply — your inline scripts will
|
914
|
-
run within a closure wrapper, so if you want to expose global variables or
|
915
|
-
functions, attach them to the <tt>window</tt> object.
|
916
|
-
</p>
|
917
|
-
|
918
|
-
<h2>
|
919
|
-
<span id="resources" class="bookmark"></span>
|
920
|
-
Examples
|
921
|
-
</h2>
|
922
|
-
|
923
|
-
<ul>
|
924
|
-
<li>
|
925
|
-
<b>frank06</b>'s <a href="http://riakjs.org/">riak-js</a>, a Node.js client for
|
926
|
-
<a href="http://www.basho.com/Riak.html">Riak</a>, with support for HTTP
|
927
|
-
and Protocol Buffers.
|
928
|
-
</li>
|
929
|
-
<li>
|
930
|
-
<b>technoweenie</b>'s <a href="https://github.com/technoweenie/coffee-resque">Coffee-Resque</a>,
|
931
|
-
a port of <a href="https://github.com/defunkt/resque">Resque</a> for Node.js.
|
932
|
-
</li>
|
933
|
-
<li>
|
934
|
-
<b>jashkenas</b>' <a href="documentation/docs/underscore.html">Underscore.coffee</a>, a port
|
935
|
-
of the <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
|
936
|
-
library of helper functions.
|
937
|
-
</li>
|
938
|
-
<li>
|
939
|
-
<b>stephank</b>'s <a href="https://github.com/stephank/orona">Orona</a>, a remake of
|
940
|
-
the Bolo tank game for modern browsers.
|
941
|
-
</li>
|
942
|
-
<li>
|
943
|
-
<b>josh</b>'s <a href="http://josh.github.com/nack/">nack</a>, a Node.js-powered
|
944
|
-
<a href="http://rack.rubyforge.org/">Rack</a> server.
|
945
|
-
</li>
|
946
|
-
<li>
|
947
|
-
<b>sstephenson</b>'s <a href="http://sstephenson.github.com/strscan-js/">StringScanner</a>,
|
948
|
-
a simple tokenizer and lexical scanner for JavaScript strings.
|
949
|
-
</li>
|
950
|
-
</ul>
|
951
|
-
|
952
|
-
<h2>
|
953
|
-
Resources
|
954
|
-
</h2>
|
955
|
-
|
956
|
-
<ul>
|
957
|
-
<li>
|
958
|
-
<a href="http://github.com/jashkenas/coffee-script/">Source Code</a><br />
|
959
|
-
Use <tt>bin/coffee</tt> to test your changes,<br />
|
960
|
-
<tt>bin/cake test</tt> to run the test suite,<br />
|
961
|
-
<tt>bin/cake build</tt> to rebuild the CoffeeScript compiler, and <br />
|
962
|
-
<tt>bin/cake build:parser</tt> to regenerate the Jison parser if you're
|
963
|
-
working on the grammar. <br /><br />
|
964
|
-
<tt>git checkout lib && bin/cake build:full</tt> is a good command to run when you're working
|
965
|
-
on the core language. It'll refresh the lib directory
|
966
|
-
(in case you broke something), build your altered compiler, use that to
|
967
|
-
rebuild itself (a good sanity test) and then run all of the tests. If
|
968
|
-
they pass, there's a good chance you've made a successful change.
|
969
|
-
</li>
|
970
|
-
<li>
|
971
|
-
<a href="http://github.com/jashkenas/coffee-script/issues">CoffeeScript Issues</a><br />
|
972
|
-
Bugs reports, feature requests, and general discussion all belong here.
|
973
|
-
</li>
|
974
|
-
<li>
|
975
|
-
If you'd like to chat, stop by <tt>#coffeescript</tt> on Freenode in the
|
976
|
-
IRC client of your choice, or on
|
977
|
-
<a href="http://webchat.freenode.net/">webchat.freenode.net</a>.
|
978
|
-
</li>
|
979
|
-
<li>
|
980
|
-
<b>satyr</b>'s <a href="http://github.com/satyr/coco">Coco</a>
|
981
|
-
— An avant-garde dialect of CoffeeScript that frequently pioneers
|
982
|
-
features and optimizations, some of which CoffeeScript later adopts.
|
983
|
-
Check out the <a href="https://github.com/satyr/coco/wiki/additions">list of additions</a>
|
984
|
-
to the language.
|
985
|
-
</li>
|
986
|
-
<li>
|
987
|
-
<b>yeungda</b>'s <a href="http://github.com/yeungda/jcoffeescript">JCoffeeScript</a>
|
988
|
-
— A Java Library that uses Rhino to compile CoffeeScript, allowing
|
989
|
-
compilation within Java projects or on systems that Node.js doesn't support.
|
990
|
-
</li>
|
991
|
-
<li>
|
992
|
-
<b>defunkt</b>'s <a href="http://github.com/defunkt/coffee-mode">CoffeeScript Major Mode</a>
|
993
|
-
— a Emacs major mode that provides syntax highlighting, indentation
|
994
|
-
support, and some bonus commands.
|
995
|
-
</li>
|
996
|
-
<li>
|
997
|
-
<b>jashkenas</b>' <a href="http://github.com/jashkenas/coffee-script-tmbundle">CoffeeScript TextMate Bundle</a>
|
998
|
-
— which provides syntax highlighting, snippet expansion, and the
|
999
|
-
ability to run bits of CoffeeScript from within TextMate itself.
|
1000
|
-
</li>
|
1001
|
-
<li>
|
1002
|
-
<b>kchmck</b>'s <a href="http://github.com/kchmck/vim-coffee-script">Vim CoffeeScript</a>
|
1003
|
-
— which adds Vim syntax highlighting and indentation support.
|
1004
|
-
</li>
|
1005
|
-
<li>
|
1006
|
-
<b>wavded</b>'s <a href="http://github.com/wavded/gedit-coffeescript">gedit-coffeescript</a>
|
1007
|
-
— a CoffeeScript syntax highlighter for the gedit text editor.
|
1008
|
-
</li>
|
1009
|
-
<li>
|
1010
|
-
<b>yeungda</b>'s <a href="http://yeungda.github.com/coffeescript-idea/">coffeescript-idea</a>
|
1011
|
-
— a plugin for IntelliJ IDEA and RubyMine providing syntax highlighting.
|
1012
|
-
</li>
|
1013
|
-
<li>
|
1014
|
-
<b>mattly</b>'s <a href="http://github.com/mattly/rack-coffee">rack-coffee</a>
|
1015
|
-
— a small Rack middleware for serving CoffeeScript files as
|
1016
|
-
compiled JavaScript on the fly.
|
1017
|
-
</li>
|
1018
|
-
<li>
|
1019
|
-
<b>jnicklas</b>'s <a href="http://github.com/jnicklas/bistro_car">BistroCar</a>
|
1020
|
-
— a plugin that serves and bundles CoffeeScript from within your
|
1021
|
-
Rails application.
|
1022
|
-
</li>
|
1023
|
-
<li>
|
1024
|
-
<b>dsc</b>'s <a href="http://github.com/dsc/coffeecup">CoffeeCup</a>
|
1025
|
-
— a Python WSGI middleware that compiles CoffeeScript to JavaScript
|
1026
|
-
on-demand during development.
|
1027
|
-
</li>
|
1028
|
-
<li>
|
1029
|
-
<b>sutto</b>'s <a href="http://github.com/Sutto/barista">Barista</a>
|
1030
|
-
— a BistroCar alternative that integrates well with
|
1031
|
-
<a href="http://documentcloud.github.com/jammit">Jammit</a> and Rails 3.
|
1032
|
-
</li>
|
1033
|
-
<li>
|
1034
|
-
<b>inem</b> and <b>gerad</b>'s <a href="http://github.com/gerad/coffee-haml-filter">coffee-haml-filter</a>
|
1035
|
-
— a custom filter for rendering CoffeeScript inline within
|
1036
|
-
<a href="http://haml-lang.com/">HAML</a> templates.
|
1037
|
-
</li>
|
1038
|
-
<li>
|
1039
|
-
<b>chrislloyd</b>'s <a href="http://github.com/chrislloyd/roast">Roast</a>
|
1040
|
-
— a CoffeeScript compiler plug-in that allows you to include external
|
1041
|
-
source files.
|
1042
|
-
</li>
|
1043
|
-
<li>
|
1044
|
-
<b>andrzejsliwa</b>'s <a href="http://github.com/andrzejsliwa/coffeeapp">CoffeeApp</a>
|
1045
|
-
— a CoffeeScript wrapper for CouchApps, web applications served
|
1046
|
-
directly from CouchDB.
|
1047
|
-
</li>
|
1048
|
-
<li>
|
1049
|
-
<b>sstephenson</b>'s <a href="http://github.com/sstephenson/eco">Eco</a>
|
1050
|
-
— high-performance embedded CoffeeScript templates, after EJS and ERB.
|
1051
|
-
</li>
|
1052
|
-
<li>
|
1053
|
-
<b>mauricemach</b>'s <a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a>
|
1054
|
-
— Markup as CoffeeScript. After _why's
|
1055
|
-
<a href="http://markaby.github.com/">Markaby</a>.
|
1056
|
-
</li>
|
1057
|
-
<li>
|
1058
|
-
<b>jashkenas</b>' <a href="http://jashkenas.github.com/docco/">Docco</a>
|
1059
|
-
— a quick-and-dirty literate-programming-style documentation generator
|
1060
|
-
for CoffeeScript. Used to produce the annotated source.
|
1061
|
-
</li>
|
1062
|
-
<li>
|
1063
|
-
<b>naturalethic</b>'s <a href="http://github.com/naturalethic/coffee-mongo">coffee-mongo</a>
|
1064
|
-
— an asynchronous MongoDB ORM, for use with Node.js and CoffeeScript.
|
1065
|
-
</li>
|
1066
|
-
<li>
|
1067
|
-
<b>mauricemach</b>'s <a href="https://github.com/mauricemach/zappa">Zappa</a>
|
1068
|
-
— a DSL for building web apps, built on top of Express and Socket.IO.
|
1069
|
-
</li>
|
1070
|
-
</ul>
|
1071
|
-
|
1072
|
-
<h2>
|
1073
|
-
<span id="webchat" class="bookmark"></span>
|
1074
|
-
Web Chat (IRC)
|
1075
|
-
</h2>
|
1076
|
-
|
1077
|
-
<p>
|
1078
|
-
Quick help and advice can usually be found in the CoffeeScript IRC room.
|
1079
|
-
Join <tt>#coffeescript</tt> on <tt>irc.freenode.net</tt>, or click the
|
1080
|
-
button below to open a webchat session on this page.
|
1081
|
-
</p>
|
1082
|
-
|
1083
|
-
<p>
|
1084
|
-
<button id="open_webchat">click to open #coffeescript</button>
|
1085
|
-
</p>
|
1086
|
-
|
1087
|
-
<h2>
|
1088
|
-
<span id="change_log" class="bookmark"></span>
|
1089
|
-
Change Log
|
1090
|
-
</h2>
|
1091
|
-
|
1092
|
-
<p>
|
1093
|
-
<b class="header" style="margin-top: 20px;">1.0.0
|
1094
|
-
<span class="timestamp"> – <small>Dec 24, 2010</small></span>
|
1095
|
-
</b>
|
1096
|
-
CoffeeScript loops no longer try to preserve block scope when functions
|
1097
|
-
are being generated within the loop body. Instead, you can use the
|
1098
|
-
<tt>do</tt> keyword to create a convenient closure wrapper.
|
1099
|
-
Added a <tt>--nodejs</tt> flag for passing through options directly
|
1100
|
-
to the <tt>node</tt> executable.
|
1101
|
-
Better behavior around the use of pure statements within expressions.
|
1102
|
-
Fixed inclusive slicing through <tt>-1</tt>, for all browsers, and splicing
|
1103
|
-
with arbitrary expressions as endpoints.
|
1104
|
-
</p>
|
1105
|
-
|
1106
|
-
<p>
|
1107
|
-
<b class="header" style="margin-top: 20px;">0.9.6
|
1108
|
-
<span class="timestamp"> – <small>Dec 6, 2010</small></span>
|
1109
|
-
</b>
|
1110
|
-
The REPL now properly formats stacktraces, and stays alive through
|
1111
|
-
asynchronous exceptions. Using <tt>--watch</tt> now prints timestamps as
|
1112
|
-
files are compiled. Fixed some accidentally-leaking variables within
|
1113
|
-
plucked closure-loops. Constructors now maintain their declaration
|
1114
|
-
location within a class body. Dynamic object keys were removed.
|
1115
|
-
Nested classes are now supported. Fixes execution context for naked
|
1116
|
-
splatted functions. Bugfix for inversion of chained comparisons.
|
1117
|
-
Chained class instantiation now works properly with splats.
|
1118
|
-
</p>
|
1119
|
-
|
1120
|
-
<p>
|
1121
|
-
<b class="header" style="margin-top: 20px;">0.9.5
|
1122
|
-
<span class="timestamp"> – <small>Nov 21, 2010</small></span>
|
1123
|
-
</b>
|
1124
|
-
0.9.5 should be considered the first release candidate for CoffeeScript 1.0.
|
1125
|
-
There have been a large number of internal changes since the previous release,
|
1126
|
-
many contributed from <b>satyr</b>'s <a href="http://github.com/satyr/coco">Coco</a>
|
1127
|
-
dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions
|
1128
|
-
can now have default arguments. Class bodies are now executable code.
|
1129
|
-
Improved syntax errors for invalid CoffeeScript. <tt>undefined</tt> now
|
1130
|
-
works like <tt>null</tt>, and cannot be assigned a new value.
|
1131
|
-
There was a precedence change with respect to single-line comprehensions:
|
1132
|
-
<tt>result = i for i in list</tt><br /> used to parse as <tt>result = (i for i in list)</tt>
|
1133
|
-
by default ... it now parses as <br /><tt>(result = i) for i in list</tt>.
|
1134
|
-
</p>
|
1135
|
-
|
1136
|
-
<p>
|
1137
|
-
<b class="header" style="margin-top: 20px;">0.9.4
|
1138
|
-
<span class="timestamp"> – <small>Sep 21, 2010</small></span>
|
1139
|
-
</b>
|
1140
|
-
CoffeeScript now uses appropriately-named temporary variables, and recycles
|
1141
|
-
their references after use. Added <tt>require.extensions</tt> support for
|
1142
|
-
<b>Node.js 0.3</b>. Loading CoffeeScript in the browser now adds just a
|
1143
|
-
single <tt>CoffeeScript</tt> object to global scope.
|
1144
|
-
Fixes for implicit object and block comment edge cases.
|
1145
|
-
</p>
|
1146
|
-
|
1147
|
-
<p>
|
1148
|
-
<b class="header" style="margin-top: 20px;">0.9.3
|
1149
|
-
<span class="timestamp"> – <small>Sep 16, 2010</small></span>
|
1150
|
-
</b>
|
1151
|
-
CoffeeScript <tt>switch</tt> statements now compile into JS <tt>switch</tt>
|
1152
|
-
statements — they previously compiled into <tt>if/else</tt> chains
|
1153
|
-
for JavaScript 1.3 compatibility.
|
1154
|
-
Soaking a function invocation is now supported. Users of the RubyMine
|
1155
|
-
editor should now be able to use <tt>--watch</tt> mode.
|
1156
|
-
</p>
|
1157
|
-
|
1158
|
-
<p>
|
1159
|
-
<b class="header" style="margin-top: 20px;">0.9.2
|
1160
|
-
<span class="timestamp"> – <small>Aug 23, 2010</small></span>
|
1161
|
-
</b>
|
1162
|
-
Specifying the start and end of a range literal is now optional, eg. <tt>array[3..]</tt>.
|
1163
|
-
You can now say <tt>a not instanceof b</tt>.
|
1164
|
-
Fixed important bugs with nested significant and non-significant indentation (Issue #637).
|
1165
|
-
Added a <tt>--require</tt> flag that allows you to hook into the <tt>coffee</tt> command.
|
1166
|
-
Added a custom <tt>jsl.conf</tt> file for our preferred JavaScriptLint setup.
|
1167
|
-
Sped up Jison grammar compilation time by flattening rules for operations.
|
1168
|
-
Block comments can now be used with JavaScript-minifier-friendly syntax.
|
1169
|
-
Added JavaScript's compound assignment bitwise operators. Bugfixes to
|
1170
|
-
implicit object literals with leading number and string keys, as the subject
|
1171
|
-
of implicit calls, and as part of compound assignment.
|
1172
|
-
</p>
|
1173
|
-
|
1174
|
-
<p>
|
1175
|
-
<b class="header" style="margin-top: 20px;">0.9.1
|
1176
|
-
<span class="timestamp"> – <small>Aug 11, 2010</small></span>
|
1177
|
-
</b>
|
1178
|
-
Bugfix release for <b>0.9.1</b>. Greatly improves the handling of mixed
|
1179
|
-
implicit objects, implicit function calls, and implicit indentation.
|
1180
|
-
String and regex interpolation is now strictly <tt>#{ ... }</tt> (Ruby style).
|
1181
|
-
The compiler now takes a <tt>--require</tt> flag, which specifies scripts
|
1182
|
-
to run before compilation.
|
1183
|
-
</p>
|
1184
|
-
|
1185
|
-
<p>
|
1186
|
-
<b class="header" style="margin-top: 20px;">0.9.0
|
1187
|
-
<span class="timestamp"> – <small>Aug 4, 2010</small></span>
|
1188
|
-
</b>
|
1189
|
-
The CoffeeScript <b>0.9</b> series is considered to be a release candidate
|
1190
|
-
for <b>1.0</b>; let's give her a shakedown cruise. <b>0.9.0</b> introduces a massive
|
1191
|
-
backwards-incompatible change: Assignment now uses <tt>=</tt>, and object
|
1192
|
-
literals use <tt>:</tt>, as in JavaScript. This allows us to have implicit
|
1193
|
-
object literals, and YAML-style object definitions. Half assignments are
|
1194
|
-
removed, in favor of <tt>+=</tt>, <tt>or=</tt>, and friends.
|
1195
|
-
Interpolation now uses a hash mark <tt>#</tt> instead of the dollar sign
|
1196
|
-
<tt>$</tt> — because dollar signs may be part of a valid JS identifier.
|
1197
|
-
Downwards range comprehensions are now safe again, and are optimized to
|
1198
|
-
straight for loops when created with integer endpoints.
|
1199
|
-
A fast, unguarded form of object comprehension was added:
|
1200
|
-
<tt>for all key, value of object</tt>. Mentioning the <tt>super</tt> keyword
|
1201
|
-
with no arguments now forwards all arguments passed to the function,
|
1202
|
-
as in Ruby. If you extend class <tt>B</tt> from parent class <tt>A</tt>, if
|
1203
|
-
<tt>A</tt> has an <tt>extended</tt> method defined, it will be called, passing in <tt>B</tt> —
|
1204
|
-
this enables static inheritance, among other things. Cleaner output for
|
1205
|
-
functions bound with the fat arrow. <tt>@variables</tt> can now be used
|
1206
|
-
in parameter lists, with the parameter being automatically set as a property
|
1207
|
-
on the object — useful in constructors and setter functions.
|
1208
|
-
Constructor functions can now take splats.
|
1209
|
-
</p>
|
1210
|
-
|
1211
|
-
<p>
|
1212
|
-
<b class="header" style="margin-top: 20px;">0.7.2
|
1213
|
-
<span class="timestamp"> – <small>Jul 12, 2010</small></span>
|
1214
|
-
</b>
|
1215
|
-
Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
|
1216
|
-
command-line options from being parsed in some circumstances.
|
1217
|
-
</p>
|
1218
|
-
|
1219
|
-
<p>
|
1220
|
-
<b class="header" style="margin-top: 20px;">0.7.1
|
1221
|
-
<span class="timestamp"> – <small>Jul 11, 2010</small></span>
|
1222
|
-
</b>
|
1223
|
-
Block-style comments are now passed through and printed as JavaScript block
|
1224
|
-
comments -- making them useful for licenses and copyright headers. Better
|
1225
|
-
support for running coffee scripts standalone via hashbangs.
|
1226
|
-
Improved syntax errors for tokens that are not in the grammar.
|
1227
|
-
</p>
|
1228
|
-
|
1229
|
-
<p>
|
1230
|
-
<b class="header" style="margin-top: 20px;">0.7.0
|
1231
|
-
<span class="timestamp"> – <small>Jun 28, 2010</small></span>
|
1232
|
-
</b>
|
1233
|
-
Official CoffeeScript variable style is now camelCase, as in JavaScript.
|
1234
|
-
Reserved words are now allowed as object keys, and will be quoted for you.
|
1235
|
-
Range comprehensions now generate cleaner code, but you have to specify <tt>by -1</tt>
|
1236
|
-
if you'd like to iterate downward. Reporting of syntax errors is greatly
|
1237
|
-
improved from the previous release. Running <tt>coffee</tt> with no arguments
|
1238
|
-
now launches the REPL, with Readline support. The <tt><-</tt> bind operator
|
1239
|
-
has been removed from CoffeeScript. The <tt>loop</tt> keyword was added,
|
1240
|
-
which is equivalent to a <tt>while true</tt> loop. Comprehensions that contain
|
1241
|
-
closures will now close over their variables, like the semantics of a <tt>forEach</tt>.
|
1242
|
-
You can now use bound function in class definitions (bound to the instance).
|
1243
|
-
For consistency, <tt>a in b</tt> is now an array presence check, and <tt>a of b</tt>
|
1244
|
-
is an object-key check. Comments are no longer passed through to the generated
|
1245
|
-
JavaScript.
|
1246
|
-
</p>
|
1247
|
-
|
1248
|
-
<p>
|
1249
|
-
<b class="header" style="margin-top: 20px;">0.6.2
|
1250
|
-
<span class="timestamp"> – <small>May 15, 2010</small></span>
|
1251
|
-
</b>
|
1252
|
-
The <tt>coffee</tt> command will now preserve directory structure when
|
1253
|
-
compiling a directory full of scripts. Fixed two omissions that were preventing
|
1254
|
-
the CoffeeScript compiler from running live within Internet Explorer.
|
1255
|
-
There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs.
|
1256
|
-
ECMA Harmony DRY-style pattern matching is now supported, where the name
|
1257
|
-
of the property is the same as the name of the value: <tt>{name, length}: func</tt>.
|
1258
|
-
Pattern matching is now allowed within comprehension variables. <tt>unless</tt>
|
1259
|
-
is now allowed in block form. <tt>until</tt> loops were added, as the inverse
|
1260
|
-
of <tt>while</tt> loops. <tt>switch</tt> statements are now allowed without
|
1261
|
-
switch object clauses. Compatible
|
1262
|
-
with Node.js <b>v0.1.95</b>.
|
1263
|
-
</p>
|
1264
|
-
|
1265
|
-
<p>
|
1266
|
-
<b class="header" style="margin-top: 20px;">0.6.1
|
1267
|
-
<span class="timestamp"> – <small>Apr 12, 2010</small></span>
|
1268
|
-
</b>
|
1269
|
-
Upgraded CoffeeScript for compatibility with the new Node.js <b>v0.1.90</b>
|
1270
|
-
series.
|
1271
|
-
</p>
|
1272
|
-
|
1273
|
-
<p>
|
1274
|
-
<b class="header" style="margin-top: 20px;">0.6.0
|
1275
|
-
<span class="timestamp"> – <small>Apr 3, 2010</small></span>
|
1276
|
-
</b>
|
1277
|
-
Trailing commas are now allowed, a-la Python. Static
|
1278
|
-
properties may be assigned directly within class definitions,
|
1279
|
-
using <tt>@property</tt> notation.
|
1280
|
-
</p>
|
1281
|
-
|
1282
|
-
<p>
|
1283
|
-
<b class="header" style="margin-top: 20px;">0.5.6
|
1284
|
-
<span class="timestamp"> – <small>Mar 23, 2010</small></span>
|
1285
|
-
</b>
|
1286
|
-
Interpolation can now be used within regular expressions and heredocs, as well as
|
1287
|
-
strings. Added the <tt><-</tt> bind operator.
|
1288
|
-
Allowing assignment to half-expressions instead of special <tt>||=</tt>-style
|
1289
|
-
operators. The arguments object is no longer automatically converted into
|
1290
|
-
an array. After requiring <tt>coffee-script</tt>, Node.js can now directly
|
1291
|
-
load <tt>.coffee</tt> files, thanks to <b>registerExtension</b>. Multiple
|
1292
|
-
splats can now be used in function calls, arrays, and pattern matching.
|
1293
|
-
</p>
|
1294
|
-
|
1295
|
-
<p>
|
1296
|
-
<b class="header" style="margin-top: 20px;">0.5.5
|
1297
|
-
<span class="timestamp"> – <small>Mar 8, 2010</small></span>
|
1298
|
-
</b>
|
1299
|
-
String interpolation, contributed by
|
1300
|
-
<a href="http://github.com/StanAngeloff">Stan Angeloff</a>.
|
1301
|
-
Since <tt>--run</tt> has been the default since <b>0.5.3</b>, updating
|
1302
|
-
<tt>--stdio</tt> and <tt>--eval</tt> to run by default, pass <tt>--compile</tt>
|
1303
|
-
as well if you'd like to print the result.
|
1304
|
-
</p>
|
1305
|
-
|
1306
|
-
<p>
|
1307
|
-
<b class="header" style="margin-top: 20px;">0.5.4
|
1308
|
-
<span class="timestamp"> – <small>Mar 3, 2010</small></span>
|
1309
|
-
</b>
|
1310
|
-
Bugfix that corrects the Node.js global constants <tt>__filename</tt> and
|
1311
|
-
<tt>__dirname</tt>. Tweaks for more flexible parsing of nested function
|
1312
|
-
literals and improperly-indented comments. Updates for the latest Node.js API.
|
1313
|
-
</p>
|
1314
|
-
|
1315
|
-
<p>
|
1316
|
-
<b class="header" style="margin-top: 20px;">0.5.3
|
1317
|
-
<span class="timestamp"> – <small>Feb 27, 2010</small></span>
|
1318
|
-
</b>
|
1319
|
-
CoffeeScript now has a syntax for defining classes. Many of the core
|
1320
|
-
components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them.
|
1321
|
-
Cakefiles can use <tt>optparse.coffee</tt> to define options for tasks.
|
1322
|
-
<tt>--run</tt> is now the default flag for the <tt>coffee</tt> command,
|
1323
|
-
use <tt>--compile</tt> to save JavaScripts. Bugfix for an ambiguity between
|
1324
|
-
RegExp literals and chained divisions.
|
1325
|
-
</p>
|
1326
|
-
|
1327
|
-
<p>
|
1328
|
-
<b class="header" style="margin-top: 20px;">0.5.2
|
1329
|
-
<span class="timestamp"> – <small>Feb 25, 2010</small></span>
|
1330
|
-
</b>
|
1331
|
-
Added a compressed version of the compiler for inclusion in web pages as
|
1332
|
-
<br /><tt>extras/coffee-script.js</tt>. It'll automatically run any script tags
|
1333
|
-
with type <tt>text/coffeescript</tt> for you. Added a <tt>--stdio</tt> option
|
1334
|
-
to the <tt>coffee</tt> command, for piped-in compiles.
|
1335
|
-
</p>
|
1336
|
-
|
1337
|
-
|
1338
|
-
<p>
|
1339
|
-
<b class="header" style="margin-top: 20px;">0.5.1
|
1340
|
-
<span class="timestamp"> – <small>Feb 24, 2010</small></span>
|
1341
|
-
</b>
|
1342
|
-
Improvements to null soaking with the existential operator, including
|
1343
|
-
soaks on indexed properties. Added conditions to <tt>while</tt> loops,
|
1344
|
-
so you can use them as filters with <tt>when</tt>, in the same manner as
|
1345
|
-
comprehensions.
|
1346
|
-
</p>
|
1347
|
-
|
1348
|
-
<p>
|
1349
|
-
<b class="header" style="margin-top: 20px;">0.5.0
|
1350
|
-
<span class="timestamp"> – <small>Feb 21, 2010</small></span>
|
1351
|
-
</b>
|
1352
|
-
CoffeeScript 0.5.0 is a major release, While there are no language changes,
|
1353
|
-
the Ruby compiler has been removed in favor of a self-hosting
|
1354
|
-
compiler written in pure CoffeeScript.
|
1355
|
-
</p>
|
1356
|
-
|
1357
|
-
<p>
|
1358
|
-
<b class="header" style="margin-top: 20px;">0.3.2
|
1359
|
-
<span class="timestamp"> – <small>Feb 8, 2010</small></span>
|
1360
|
-
</b>
|
1361
|
-
<tt>@property</tt> is now a shorthand for <tt>this.property</tt>.<br />
|
1362
|
-
Switched the default JavaScript engine from Narwhal to Node.js. Pass
|
1363
|
-
the <tt>--narwhal</tt> flag if you'd like to continue using it.
|
1364
|
-
</p>
|
1365
|
-
|
1366
|
-
<p>
|
1367
|
-
<b class="header" style="margin-top: 20px;">0.3.0
|
1368
|
-
<span class="timestamp"> – <small>Jan 26, 2010</small></span>
|
1369
|
-
</b>
|
1370
|
-
CoffeeScript 0.3 includes major syntax changes:
|
1371
|
-
<br />
|
1372
|
-
The function symbol was changed to
|
1373
|
-
<tt>-></tt>, and the bound function symbol is now <tt>=></tt>.
|
1374
|
-
<br />
|
1375
|
-
Parameter lists in function definitions must now be wrapped in parentheses.
|
1376
|
-
<br />
|
1377
|
-
Added property soaking, with the <tt>?.</tt> operator.
|
1378
|
-
<br />
|
1379
|
-
Made parentheses optional, when invoking functions with arguments.
|
1380
|
-
<br />
|
1381
|
-
Removed the obsolete block literal syntax.
|
1382
|
-
</p>
|
1383
|
-
|
1384
|
-
<p>
|
1385
|
-
<b class="header" style="margin-top: 20px;">0.2.6
|
1386
|
-
<span class="timestamp"> – <small>Jan 17, 2010</small></span>
|
1387
|
-
</b>
|
1388
|
-
Added Python-style chained comparisons, the conditional existence
|
1389
|
-
operator <tt>?=</tt>, and some examples from <i>Beautiful Code</i>.
|
1390
|
-
Bugfixes relating to statement-to-expression conversion, arguments-to-array
|
1391
|
-
conversion, and the TextMate syntax highlighter.
|
1392
|
-
</p>
|
1393
|
-
|
1394
|
-
<p>
|
1395
|
-
<b class="header" style="margin-top: 20px;">0.2.5
|
1396
|
-
<span class="timestamp"> – <small>Jan 13, 2010</small></span>
|
1397
|
-
</b>
|
1398
|
-
The conditions in switch statements can now take multiple values at once —
|
1399
|
-
If any of them are true, the case will run. Added the long arrow <tt>==></tt>,
|
1400
|
-
which defines and immediately binds a function to <tt>this</tt>. While loops can
|
1401
|
-
now be used as expressions, in the same way that comprehensions can. Splats
|
1402
|
-
can be used within pattern matches to soak up the rest of an array.
|
1403
|
-
</p>
|
1404
|
-
|
1405
|
-
<p>
|
1406
|
-
<b class="header" style="margin-top: 20px;">0.2.4
|
1407
|
-
<span class="timestamp"> – <small>Jan 12, 2010</small></span>
|
1408
|
-
</b>
|
1409
|
-
Added ECMAScript Harmony style destructuring assignment, for dealing with
|
1410
|
-
extracting values from nested arrays and objects. Added indentation-sensitive
|
1411
|
-
heredocs for nicely formatted strings or chunks of code.
|
1412
|
-
</p>
|
1413
|
-
|
1414
|
-
<p>
|
1415
|
-
<b class="header" style="margin-top: 20px;">0.2.3
|
1416
|
-
<span class="timestamp"> – <small>Jan 11, 2010</small></span>
|
1417
|
-
</b>
|
1418
|
-
Axed the unsatisfactory <tt>ino</tt> keyword, replacing it with <tt>of</tt> for
|
1419
|
-
object comprehensions. They now look like: <tt>for prop, value of object</tt>.
|
1420
|
-
</p>
|
1421
|
-
|
1422
|
-
<p>
|
1423
|
-
<b class="header" style="margin-top: 20px;">0.2.2
|
1424
|
-
<span class="timestamp"> – <small>Jan 10, 2010</small></span>
|
1425
|
-
</b>
|
1426
|
-
When performing a comprehension over an object, use <tt>ino</tt>, instead
|
1427
|
-
of <tt>in</tt>, which helps us generate smaller, more efficient code at
|
1428
|
-
compile time.
|
1429
|
-
<br />
|
1430
|
-
Added <tt>::</tt> as a shorthand for saying <tt>.prototype.</tt>
|
1431
|
-
<br />
|
1432
|
-
The "splat" symbol has been changed from a prefix asterisk <tt>*</tt>, to
|
1433
|
-
a postfix ellipsis <tt>...</tt>
|
1434
|
-
<br />
|
1435
|
-
Added JavaScript's <tt>in</tt> operator,
|
1436
|
-
empty <tt>return</tt> statements, and empty <tt>while</tt> loops.
|
1437
|
-
<br />
|
1438
|
-
Constructor functions that start with capital letters now include a
|
1439
|
-
safety check to make sure that the new instance of the object is returned.
|
1440
|
-
<br />
|
1441
|
-
The <tt>extends</tt> keyword now functions identically to <tt>goog.inherits</tt>
|
1442
|
-
in Google's Closure Library.
|
1443
|
-
</p>
|
1444
|
-
|
1445
|
-
<p>
|
1446
|
-
<b class="header" style="margin-top: 20px;">0.2.1
|
1447
|
-
<span class="timestamp"> – <small>Jan 5, 2010</small></span>
|
1448
|
-
</b>
|
1449
|
-
Arguments objects are now converted into real arrays when referenced.
|
1450
|
-
</p>
|
1451
|
-
|
1452
|
-
<p>
|
1453
|
-
<b class="header" style="margin-top: 20px;">0.2.0
|
1454
|
-
<span class="timestamp"> – <small>Jan 5, 2010</small></span>
|
1455
|
-
</b>
|
1456
|
-
Major release. Significant whitespace. Better statement-to-expression
|
1457
|
-
conversion. Splats. Splice literals. Object comprehensions. Blocks.
|
1458
|
-
The existential operator. Many thanks to all the folks who posted issues,
|
1459
|
-
with special thanks to
|
1460
|
-
<a href="http://github.com/liamoc">Liam O'Connor-Davis</a> for whitespace
|
1461
|
-
and expression help.
|
1462
|
-
</p>
|
1463
|
-
|
1464
|
-
<p>
|
1465
|
-
<b class="header" style="margin-top: 20px;">0.1.6
|
1466
|
-
<span class="timestamp"> – <small>Dec 27, 2009</small></span>
|
1467
|
-
</b>
|
1468
|
-
Bugfix for running <tt>coffee --interactive</tt> and <tt>--run</tt>
|
1469
|
-
from outside of the CoffeeScript directory. Bugfix for nested
|
1470
|
-
function/if-statements.
|
1471
|
-
</p>
|
1472
|
-
|
1473
|
-
<p>
|
1474
|
-
<b class="header" style="margin-top: 20px;">0.1.5
|
1475
|
-
<span class="timestamp"> – <small>Dec 26, 2009</small></span>
|
1476
|
-
</b>
|
1477
|
-
Array slice literals and array comprehensions can now both take Ruby-style
|
1478
|
-
ranges to specify the start and end. JavaScript variable declaration is
|
1479
|
-
now pushed up to the top of the scope, making all assignment statements into
|
1480
|
-
expressions. You can use <tt>\</tt> to escape newlines.
|
1481
|
-
The <tt>coffee-script</tt> command is now called <tt>coffee</tt>.
|
1482
|
-
</p>
|
1483
|
-
|
1484
|
-
<p>
|
1485
|
-
<b class="header" style="margin-top: 20px;">0.1.4
|
1486
|
-
<span class="timestamp"> – <small>Dec 25, 2009</small></span>
|
1487
|
-
</b>
|
1488
|
-
The official CoffeeScript extension is now <tt>.coffee</tt> instead of
|
1489
|
-
<tt>.cs</tt>, which properly belongs to
|
1490
|
-
<a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a>.
|
1491
|
-
Due to popular demand, you can now also use <tt>=</tt> to assign. Unlike
|
1492
|
-
JavaScript, <tt>=</tt> can also be used within object literals, interchangeably
|
1493
|
-
with <tt>:</tt>. Made a grammatical fix for chained function calls
|
1494
|
-
like <tt>func(1)(2)(3)(4)</tt>. Inheritance and super no longer use
|
1495
|
-
<tt>__proto__</tt>, so they should be IE-compatible now.
|
1496
|
-
</p>
|
1497
|
-
|
1498
|
-
<p>
|
1499
|
-
<b class="header" style="margin-top: 20px;">0.1.3
|
1500
|
-
<span class="timestamp"> – <small>Dec 25, 2009</small></span>
|
1501
|
-
</b>
|
1502
|
-
The <tt>coffee</tt> command now includes <tt>--interactive</tt>,
|
1503
|
-
which launches an interactive CoffeeScript session, and <tt>--run</tt>,
|
1504
|
-
which directly compiles and executes a script. Both options depend on a
|
1505
|
-
working installation of Narwhal.
|
1506
|
-
The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
|
1507
|
-
together a little smoother with <tt>is</tt>.
|
1508
|
-
Quoted strings are now allowed as identifiers within object literals: eg.
|
1509
|
-
<tt>{"5+5": 10}</tt>.
|
1510
|
-
All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
|
1511
|
-
<tt>*:</tt>, etc.
|
1512
|
-
</p>
|
1513
|
-
|
1514
|
-
<p>
|
1515
|
-
<b class="header" style="margin-top: 20px;">0.1.2
|
1516
|
-
<span class="timestamp"> – <small>Dec 24, 2009</small></span>
|
1517
|
-
</b>
|
1518
|
-
Fixed a bug with calling <tt>super()</tt> through more than one level of
|
1519
|
-
inheritance, with the re-addition of the <tt>extends</tt> keyword.
|
1520
|
-
Added experimental <a href="http://narwhaljs.org/">Narwhal</a>
|
1521
|
-
support (as a Tusk package), contributed by
|
1522
|
-
<a href="http://tlrobinson.net/">Tom Robinson</a>, including
|
1523
|
-
<b>bin/cs</b> as a CoffeeScript REPL and interpreter.
|
1524
|
-
New <tt>--no-wrap</tt> option to suppress the safety function
|
1525
|
-
wrapper.
|
1526
|
-
</p>
|
1527
|
-
|
1528
|
-
<p>
|
1529
|
-
<b class="header" style="margin-top: 20px;">0.1.1
|
1530
|
-
<span class="timestamp"> – <small>Dec 24, 2009</small></span>
|
1531
|
-
</b>
|
1532
|
-
Added <tt>instanceof</tt> and <tt>typeof</tt> as operators.
|
1533
|
-
</p>
|
1534
|
-
|
1535
|
-
<p>
|
1536
|
-
<b class="header" style="margin-top: 20px;">0.1.0
|
1537
|
-
<span class="timestamp"> – <small>Dec 24, 2009</small></span>
|
1538
|
-
</b>
|
1539
|
-
Initial CoffeeScript release.
|
1540
|
-
</p>
|
1541
|
-
|
1542
|
-
</div>
|
1543
|
-
|
1544
|
-
<script type="text/coffeescript">
|
1545
|
-
|
1546
|
-
# Set up the compilation function, to run when you stop typing.
|
1547
|
-
compileSource = ->
|
1548
|
-
source = $('#repl_source').val()
|
1549
|
-
window.compiledJS = ''
|
1550
|
-
try
|
1551
|
-
window.compiledJS = CoffeeScript.compile source, bare: on
|
1552
|
-
el = $('#repl_results')[0]
|
1553
|
-
if el.innerText
|
1554
|
-
el.innerText = window.compiledJS
|
1555
|
-
else
|
1556
|
-
$(el).text window.compiledJS
|
1557
|
-
$('#error').hide()
|
1558
|
-
catch error
|
1559
|
-
$('#error').text(error.message).show()
|
1560
|
-
|
1561
|
-
# Listen for keypresses and recompile.
|
1562
|
-
$('#repl_source').keyup -> compileSource()
|
1563
|
-
|
1564
|
-
# Eval the compiled js.
|
1565
|
-
$('.minibutton.run').click ->
|
1566
|
-
try
|
1567
|
-
eval window.compiledJS
|
1568
|
-
catch error then alert error
|
1569
|
-
|
1570
|
-
# Load the console with a string of CoffeeScript.
|
1571
|
-
window.loadConsole = (coffee) ->
|
1572
|
-
$('#repl_source').val coffee
|
1573
|
-
compileSource()
|
1574
|
-
$('.navigation.try').addClass('active')
|
1575
|
-
false
|
1576
|
-
|
1577
|
-
# Helper to hide the menus.
|
1578
|
-
closeMenus = ->
|
1579
|
-
$('.navigation.active').removeClass 'active'
|
1580
|
-
|
1581
|
-
# Bind navigation buttons to open the menus.
|
1582
|
-
$('.navigation').click (e) ->
|
1583
|
-
return if e.target.tagName.toLowerCase() is 'a'
|
1584
|
-
return false if $(e.target).closest('.repl_wrapper').length
|
1585
|
-
if $(this).hasClass('active')
|
1586
|
-
closeMenus()
|
1587
|
-
else
|
1588
|
-
closeMenus()
|
1589
|
-
$(this).addClass 'active'
|
1590
|
-
false
|
1591
|
-
|
1592
|
-
$(document.body).click (e) ->
|
1593
|
-
return false if $(e.target).hasClass('minibutton')
|
1594
|
-
closeMenus()
|
1595
|
-
|
1596
|
-
$('#open_webchat').click ->
|
1597
|
-
$(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
|
1598
|
-
|
1599
|
-
compileSource()
|
1600
|
-
|
1601
|
-
</script>
|
1602
|
-
|
1603
|
-
<script src="documentation/vendor/jquery-1.4.2.js"></script>
|
1604
|
-
<script src="extras/coffee-script.js"></script>
|
1605
|
-
|
1606
|
-
</body>
|
1607
|
-
</html>
|