From 980a663c1952f0fafde07eaf8d454c0446833979 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 29 Jul 2010 00:51:35 -0400 Subject: [PATCH] ported and regenerated examples. --- Rakefile | 2 +- documentation/coffee/aliases.coffee | 4 +- .../coffee/array_comprehensions.coffee | 2 +- documentation/coffee/assignment.coffee | 4 +- documentation/coffee/cake_tasks.coffee | 8 +- documentation/coffee/classes.coffee | 12 +- documentation/coffee/comparisons.coffee | 4 +- documentation/coffee/conditionals.coffee | 8 +- documentation/coffee/embedded.coffee | 2 +- documentation/coffee/existence.coffee | 2 +- documentation/coffee/expressions.coffee | 4 +- .../coffee/expressions_assignment.coffee | 2 +- .../coffee/expressions_comprehension.coffee | 2 +- documentation/coffee/fat_arrow.coffee | 6 +- documentation/coffee/functions.coffee | 4 +- documentation/coffee/heredocs.coffee | 10 +- documentation/coffee/interpolation.coffee | 4 +- .../coffee/interpolation_expression.coffee | 6 +- .../coffee/multiple_return_values.coffee | 4 +- .../coffee/object_comprehensions.coffee | 4 +- documentation/coffee/object_extraction.coffee | 8 +- .../coffee/objects_and_arrays.coffee | 9 +- documentation/coffee/objects_reserved.coffee | 2 +- documentation/coffee/overview.coffee | 17 +- .../coffee/parallel_assignment.coffee | 6 +- .../coffee/patterns_and_splats.coffee | 4 +- documentation/coffee/prototypes.coffee | 4 +- .../coffee/range_comprehensions.coffee | 8 +- documentation/coffee/scope.coffee | 10 +- documentation/coffee/slices.coffee | 6 +- documentation/coffee/splats.coffee | 12 +- documentation/coffee/splices.coffee | 4 +- documentation/coffee/strings.coffee | 2 +- documentation/coffee/while.coffee | 4 +- documentation/index.html.erb | 13 +- documentation/js/aliases.js | 32 +- documentation/js/array_comprehensions.js | 40 +- documentation/js/assignment.js | 8 +- documentation/js/block_comment.js | 10 +- documentation/js/cake_tasks.js | 22 +- documentation/js/classes.js | 61 ++- documentation/js/comparisons.js | 8 +- documentation/js/conditionals.js | 24 +- documentation/js/embedded.js | 8 +- documentation/js/existence.js | 12 +- documentation/js/expressions.js | 24 +- documentation/js/expressions_assignment.js | 6 +- documentation/js/expressions_comprehension.js | 23 +- documentation/js/expressions_try.js | 16 +- documentation/js/fat_arrow.js | 24 +- documentation/js/functions.js | 16 +- documentation/js/heredocs.js | 6 +- documentation/js/interpolation.js | 8 +- documentation/js/interpolation_expression.js | 10 +- documentation/js/multiple_return_values.js | 18 +- documentation/js/object_comprehensions.js | 34 +- documentation/js/object_extraction.js | 32 +- documentation/js/objects_and_arrays.js | 22 +- documentation/js/objects_reserved.js | 8 +- documentation/js/overview.js | 67 ++- documentation/js/parallel_assignment.js | 14 +- documentation/js/patterns_and_splats.js | 16 +- documentation/js/prototypes.js | 8 +- documentation/js/range_comprehensions.js | 38 +- documentation/js/scope.js | 19 +- documentation/js/slices.js | 10 +- documentation/js/soaks.js | 6 +- documentation/js/splats.js | 33 +- documentation/js/splices.js | 8 +- documentation/js/strings.js | 8 +- documentation/js/switch.js | 32 +- documentation/js/try.js | 18 +- documentation/js/while.js | 34 +- index.html | 421 ++++++++---------- 74 files changed, 652 insertions(+), 755 deletions(-) diff --git a/Rakefile b/Rakefile index 8c6b8fc8..796c9649 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ EOS desc "Build the documentation page" task :doc do source = 'documentation/index.html.erb' - child = fork { exec "bin/coffee -cw -o documentation/js documentation/coffee/*.coffee" } + child = fork { exec "bin/coffee --no-wrap -cw -o documentation/js documentation/coffee/*.coffee" } at_exit { Process.kill("INT", child) } Signal.trap("INT") { exit } loop do diff --git a/documentation/coffee/aliases.coffee b/documentation/coffee/aliases.coffee index 0bf81324..4c274ef9 100644 --- a/documentation/coffee/aliases.coffee +++ b/documentation/coffee/aliases.coffee @@ -1,11 +1,11 @@ launch() if ignition is on -volume: 10 if band isnt SpinalTap +volume = 10 if band isnt SpinalTap letTheWildRumpusBegin() unless answer is no if car.speed < limit then accelerate() -winner: yes if pick in [47, 92, 13] +winner = yes if pick in [47, 92, 13] print "My name is " + @name diff --git a/documentation/coffee/array_comprehensions.coffee b/documentation/coffee/array_comprehensions.coffee index 1967b8f7..3ea7bd59 100644 --- a/documentation/coffee/array_comprehensions.coffee +++ b/documentation/coffee/array_comprehensions.coffee @@ -1,5 +1,5 @@ # Eat lunch. -lunch: eat food for food in ['toast', 'cheese', 'wine'] +lunch = eat food for food in ['toast', 'cheese', 'wine'] # Naive collision detection. for roid in asteroids diff --git a/documentation/coffee/assignment.coffee b/documentation/coffee/assignment.coffee index db979f5c..c0b8c3c9 100644 --- a/documentation/coffee/assignment.coffee +++ b/documentation/coffee/assignment.coffee @@ -1,2 +1,2 @@ -greeting: "Hello CoffeeScript" -difficulty: 0.5 +greeting = "Hello CoffeeScript" +difficulty = 0.5 diff --git a/documentation/coffee/cake_tasks.coffee b/documentation/coffee/cake_tasks.coffee index f4d125e3..04089ff8 100644 --- a/documentation/coffee/cake_tasks.coffee +++ b/documentation/coffee/cake_tasks.coffee @@ -1,9 +1,9 @@ -fs: require 'fs' +fs = require 'fs' option '-o', '--output [DIR]', 'directory for compiled code' task 'build:parser', 'rebuild the Jison parser', -> require 'jison' - code: require('./lib/grammar').parser.generate() - dir: options.output or 'lib' - fs.writeFile "$dir/parser.js", code \ No newline at end of file + code = require('./lib/grammar').parser.generate() + dir = options.output or 'lib' + fs.writeFile "#dir/parser.js", code \ No newline at end of file diff --git a/documentation/coffee/classes.coffee b/documentation/coffee/classes.coffee index 6a5fd3c5..6794518a 100644 --- a/documentation/coffee/classes.coffee +++ b/documentation/coffee/classes.coffee @@ -1,25 +1,21 @@ class Animal + constructor: (@name) -> + move: (meters) -> alert @name + " moved " + meters + "m." class Snake extends Animal - constructor: (name) -> - @name: name - move: -> alert "Slithering..." super 5 class Horse extends Animal - constructor: (name) -> - @name: name - move: -> alert "Galloping..." super 45 -sam: new Snake "Sammy the Python" -tom: new Horse "Tommy the Palomino" +sam = new Snake "Sammy the Python" +tom = new Horse "Tommy the Palomino" sam.move() tom.move() diff --git a/documentation/coffee/comparisons.coffee b/documentation/coffee/comparisons.coffee index d3e165a3..6cac549c 100644 --- a/documentation/coffee/comparisons.coffee +++ b/documentation/coffee/comparisons.coffee @@ -1,5 +1,5 @@ -cholesterol: 127 +cholesterol = 127 -healthy: 200 > cholesterol > 60 +healthy = 200 > cholesterol > 60 diff --git a/documentation/coffee/conditionals.coffee b/documentation/coffee/conditionals.coffee index 2b64c758..5f7e4385 100644 --- a/documentation/coffee/conditionals.coffee +++ b/documentation/coffee/conditionals.coffee @@ -1,9 +1,11 @@ -mood: greatlyImproved if singing +mood = greatlyImproved if singing if happy and knowsIt clapsHands() chaChaCha() +else + showIt() -date: if friday then sue else jill +date = if friday then sue else jill -options: or defaultOptions \ No newline at end of file +options = or defaults \ No newline at end of file diff --git a/documentation/coffee/embedded.coffee b/documentation/coffee/embedded.coffee index 17910189..bb16b79d 100644 --- a/documentation/coffee/embedded.coffee +++ b/documentation/coffee/embedded.coffee @@ -1,4 +1,4 @@ -hi: `function() { +hi = `function() { return [document.title, "Hello JavaScript"].join(": "); }` diff --git a/documentation/coffee/existence.coffee b/documentation/coffee/existence.coffee index febbadb9..d4405e38 100644 --- a/documentation/coffee/existence.coffee +++ b/documentation/coffee/existence.coffee @@ -1,4 +1,4 @@ -solipsism: true if mind? and not world? +solipsism = true if mind? and not world? speed ?= 140 diff --git a/documentation/coffee/expressions.coffee b/documentation/coffee/expressions.coffee index 0e184fd2..f4e59c4f 100644 --- a/documentation/coffee/expressions.coffee +++ b/documentation/coffee/expressions.coffee @@ -1,4 +1,4 @@ -grade: (student) -> +grade = (student) -> if student.excellentWork "A+" else if student.okayStuff @@ -6,4 +6,4 @@ grade: (student) -> else "C" -eldest: if 24 > 21 then "Liz" else "Ike" \ No newline at end of file +eldest = if 24 > 21 then "Liz" else "Ike" \ No newline at end of file diff --git a/documentation/coffee/expressions_assignment.coffee b/documentation/coffee/expressions_assignment.coffee index b8ecf4e3..0ba0daa5 100644 --- a/documentation/coffee/expressions_assignment.coffee +++ b/documentation/coffee/expressions_assignment.coffee @@ -1 +1 @@ -six: (one: 1) + (two: 2) + (three: 3) \ No newline at end of file +six = (one = 1) + (two = 2) + (three = 3) \ No newline at end of file diff --git a/documentation/coffee/expressions_comprehension.coffee b/documentation/coffee/expressions_comprehension.coffee index 4c51e3f5..0af075d3 100644 --- a/documentation/coffee/expressions_comprehension.coffee +++ b/documentation/coffee/expressions_comprehension.coffee @@ -1,3 +1,3 @@ # The first ten global properties. -globals: (name for name of window)[0...10] \ No newline at end of file +globals = (name for name of window)[0...10] \ No newline at end of file diff --git a/documentation/coffee/fat_arrow.coffee b/documentation/coffee/fat_arrow.coffee index 28bbf12a..836eb7a6 100644 --- a/documentation/coffee/fat_arrow.coffee +++ b/documentation/coffee/fat_arrow.coffee @@ -1,6 +1,6 @@ -Account: (customer, cart) -> - @customer: customer - @cart: cart +Account = (customer, cart) -> + @customer = customer + @cart = cart $('.shopping_cart').bind 'click', (event) => @customer.purchase @cart \ No newline at end of file diff --git a/documentation/coffee/functions.coffee b/documentation/coffee/functions.coffee index 4fd48d32..60cc7ca4 100644 --- a/documentation/coffee/functions.coffee +++ b/documentation/coffee/functions.coffee @@ -1,2 +1,2 @@ -square: (x) -> x * x -cube: (x) -> square(x) * x +square = (x) -> x * x +cube = (x) -> square(x) * x diff --git a/documentation/coffee/heredocs.coffee b/documentation/coffee/heredocs.coffee index 10769ea6..ec76c149 100644 --- a/documentation/coffee/heredocs.coffee +++ b/documentation/coffee/heredocs.coffee @@ -1,5 +1,5 @@ -html: ''' - - cup of coffeescript - - ''' \ No newline at end of file +html = ''' + + cup of coffeescript + + ''' \ No newline at end of file diff --git a/documentation/coffee/interpolation.coffee b/documentation/coffee/interpolation.coffee index 63f2c608..df3571d0 100644 --- a/documentation/coffee/interpolation.coffee +++ b/documentation/coffee/interpolation.coffee @@ -1,2 +1,2 @@ -author: "Wittgenstein" -quote: "A picture is a fact. -- $author" \ No newline at end of file +author = "Wittgenstein" +quote = "A picture is a fact. -- #author" \ No newline at end of file diff --git a/documentation/coffee/interpolation_expression.coffee b/documentation/coffee/interpolation_expression.coffee index 19b0da87..1e5e357f 100644 --- a/documentation/coffee/interpolation_expression.coffee +++ b/documentation/coffee/interpolation_expression.coffee @@ -1,6 +1,6 @@ -sentence: "${ 22 / 7 } is a decent approximation of π" +sentence = "#{ 22 / 7 } is a decent approximation of π" -sep: "[.\\/\\- ]" -dates: /\d+$sep\d+$sep\d+/g +sep = "[.\\/\\- ]" +dates = /\d+$sep\d+$sep\d+/g diff --git a/documentation/coffee/multiple_return_values.coffee b/documentation/coffee/multiple_return_values.coffee index b6153f77..ec350bae 100644 --- a/documentation/coffee/multiple_return_values.coffee +++ b/documentation/coffee/multiple_return_values.coffee @@ -1,5 +1,5 @@ -weatherReport: (location) -> +weatherReport = (location) -> # Make an Ajax request to fetch the weather... [location, 72, "Mostly Sunny"] -[city, temp, forecast]: weatherReport "Berkeley, CA" \ No newline at end of file +[city, temp, forecast] = weatherReport "Berkeley, CA" \ No newline at end of file diff --git a/documentation/coffee/object_comprehensions.coffee b/documentation/coffee/object_comprehensions.coffee index 7dd549d0..f5e2ce89 100644 --- a/documentation/coffee/object_comprehensions.coffee +++ b/documentation/coffee/object_comprehensions.coffee @@ -1,4 +1,4 @@ -yearsOld: {max: 10, ida: 9, tim: 11} +yearsOld = max: 10, ida: 9, tim: 11 -ages: for child, age of yearsOld +ages = for child, age of yearsOld child + " is " + age \ No newline at end of file diff --git a/documentation/coffee/object_extraction.coffee b/documentation/coffee/object_extraction.coffee index c8e1e153..d3625d67 100644 --- a/documentation/coffee/object_extraction.coffee +++ b/documentation/coffee/object_extraction.coffee @@ -1,13 +1,11 @@ -futurists: { +futurists = sculptor: "Umberto Boccioni" painter: "Vladimir Burliuk" - poet: { + poet: name: "F.T. Marinetti" address: [ "Via Roma 42R" "Bellagio, Italy 22021" ] - } -} -{poet: {name, address: [street, city]}}: futurists \ No newline at end of file +{poet: {name, address: [street, city]}} = futurists \ No newline at end of file diff --git a/documentation/coffee/objects_and_arrays.coffee b/documentation/coffee/objects_and_arrays.coffee index f66a8a25..351fa75a 100644 --- a/documentation/coffee/objects_and_arrays.coffee +++ b/documentation/coffee/objects_and_arrays.coffee @@ -1,12 +1,13 @@ -song: ["do", "re", "mi", "fa", "so"] +song = ["do", "re", "mi", "fa", "so"] -ages: { +singers = {Jagger: 'Rock', Elvis: 'Roll'} + +ages = max: 10 ida: 9 tim: 11 -} -matrix: [ +matrix = [ 1, 0, 1 0, 0, 1 1, 1, 0 diff --git a/documentation/coffee/objects_reserved.coffee b/documentation/coffee/objects_reserved.coffee index 86fcc51b..492b80a2 100644 --- a/documentation/coffee/objects_reserved.coffee +++ b/documentation/coffee/objects_reserved.coffee @@ -1 +1 @@ -$('.account').css {class: 'active'} \ No newline at end of file +$('.account').css class: 'active' \ No newline at end of file diff --git a/documentation/coffee/overview.coffee b/documentation/coffee/overview.coffee index 0a4d894e..7ab4e716 100644 --- a/documentation/coffee/overview.coffee +++ b/documentation/coffee/overview.coffee @@ -1,29 +1,28 @@ # Assignment: -number: 42 -opposite: true +number = 42 +opposite = true # Conditions: -number: -42 if opposite +number = -42 if opposite # Functions: -square: (x) -> x * x +square = (x) -> x * x # Arrays: -list: [1, 2, 3, 4, 5] +list = [1, 2, 3, 4, 5] # Objects: -math: { +math = root: Math.sqrt square: square cube: (x) -> x * square x -} # Splats: -race: (winner, runners...) -> +race = (winner, runners...) -> print winner, runners # Existence: alert "I knew it!" if elvis? # Array comprehensions: -cubes: math.cube num for num in list +cubes = math.cube num for num in list diff --git a/documentation/coffee/parallel_assignment.coffee b/documentation/coffee/parallel_assignment.coffee index 0f8e09c4..bbe03a8d 100644 --- a/documentation/coffee/parallel_assignment.coffee +++ b/documentation/coffee/parallel_assignment.coffee @@ -1,4 +1,4 @@ -theBait: 1000 -theSwitch: 0 +theBait = 1000 +theSwitch = 0 -[theBait, theSwitch]: [theSwitch, theBait] \ No newline at end of file +[theBait, theSwitch] = [theSwitch, theBait] \ No newline at end of file diff --git a/documentation/coffee/patterns_and_splats.coffee b/documentation/coffee/patterns_and_splats.coffee index b18cf23b..12eb818f 100644 --- a/documentation/coffee/patterns_and_splats.coffee +++ b/documentation/coffee/patterns_and_splats.coffee @@ -1,6 +1,6 @@ -tag: "" +tag = "" -[open, contents..., close]: tag.split("") +[open, contents..., close] = tag.split("") diff --git a/documentation/coffee/prototypes.coffee b/documentation/coffee/prototypes.coffee index bf0d0a8a..ebefb17b 100644 --- a/documentation/coffee/prototypes.coffee +++ b/documentation/coffee/prototypes.coffee @@ -1,2 +1,2 @@ -String::dasherize: -> - this.replace(/_/g, "-") \ No newline at end of file +String::dasherize = -> + this.replace /_/g, "-" \ No newline at end of file diff --git a/documentation/coffee/range_comprehensions.coffee b/documentation/coffee/range_comprehensions.coffee index 10cd0410..d5e0b68e 100644 --- a/documentation/coffee/range_comprehensions.coffee +++ b/documentation/coffee/range_comprehensions.coffee @@ -1,6 +1,6 @@ -countdown: num for num in [10..1] +countdown = num for num in [10..1] -deliverEggs: -> +deliverEggs = -> for i in [0...eggs.length] by 12 - dozen: eggs[i...i+12] - deliver new eggCarton(dozen) + dozen = eggs[i...i+12] + deliver new eggCarton dozen diff --git a/documentation/coffee/scope.coffee b/documentation/coffee/scope.coffee index 5290c0d7..d0a5f1e6 100644 --- a/documentation/coffee/scope.coffee +++ b/documentation/coffee/scope.coffee @@ -1,5 +1,5 @@ -outer: 1 -changeNumbers: -> - inner: -1 - outer: 10 -inner: changeNumbers() \ No newline at end of file +outer = 1 +changeNumbers = -> + inner = -1 + outer = 10 +inner = changeNumbers() \ No newline at end of file diff --git a/documentation/coffee/slices.coffee b/documentation/coffee/slices.coffee index ef6a0bcf..794e8e04 100644 --- a/documentation/coffee/slices.coffee +++ b/documentation/coffee/slices.coffee @@ -1,6 +1,6 @@ -numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -threeToSix: numbers[3..6] +threeToSix = numbers[3..6] -copy: numbers[0...numbers.length] +copy = numbers[0...numbers.length] diff --git a/documentation/coffee/splats.coffee b/documentation/coffee/splats.coffee index ee9b507c..c48a3cdc 100644 --- a/documentation/coffee/splats.coffee +++ b/documentation/coffee/splats.coffee @@ -1,11 +1,11 @@ -gold: silver: rest: "unknown" +gold = silver = rest = "unknown" -awardMedals: (first, second, rest...) -> - gold: first - silver: second - rest: rest +awardMedals = (first, second, others...) -> + gold = first + silver = second + rest = others -contenders: [ +contenders = [ "Michael Phelps" "Liu Xiang" "Yao Ming" diff --git a/documentation/coffee/splices.coffee b/documentation/coffee/splices.coffee index 745237ae..ecf9d578 100644 --- a/documentation/coffee/splices.coffee +++ b/documentation/coffee/splices.coffee @@ -1,5 +1,5 @@ -numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -numbers[3..6]: [-3, -4, -5, -6] +numbers[3..6] = [-3, -4, -5, -6] diff --git a/documentation/coffee/strings.coffee b/documentation/coffee/strings.coffee index 1ec06723..77813758 100644 --- a/documentation/coffee/strings.coffee +++ b/documentation/coffee/strings.coffee @@ -1,4 +1,4 @@ -mobyDick: "Call me Ishmael. Some years ago -- +mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail diff --git a/documentation/coffee/while.coffee b/documentation/coffee/while.coffee index 29f6e13c..81b12cbc 100644 --- a/documentation/coffee/while.coffee +++ b/documentation/coffee/while.coffee @@ -4,7 +4,7 @@ if this.studyingEconomics sell() until supply > demand # Nursery Rhyme -num: 6 -lyrics: while num: - 1 +num = 6 +lyrics = while num -= 1 num + " little monkeys, jumping on the bed. One fell out and bumped his head." diff --git a/documentation/index.html.erb b/documentation/index.html.erb index b84d1d1a..1ec16f46 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -1,10 +1,9 @@ <% require 'uv' def code_for(file, executable=false) - @stripper ||= /(\A\(function\(\)\{\n|\}\)\(\);\n*\Z|^ )/ return '' unless File.exists?("documentation/js/#{file}.js") cs = File.read("documentation/coffee/#{file}.coffee") - js = File.read("documentation/js/#{file}.js").gsub(@stripper, '') + js = File.read("documentation/js/#{file}.js") cshtml = Uv.parse(cs, 'xhtml', 'coffeescript', false, 'idle', false) jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false) append = executable == true ? '' : "alert(#{executable});" @@ -793,9 +792,9 @@ coffee --print app/scripts/*.coffee > concatenation.js Double-quoted heredocs, like double-quoted strings, allow interpolation.

- Sometimes you'd like to pass a block comment through to the generated - JavaScript. For example, when you need to embed a licensing header at - the top of a file. Block comments, which mirror the synax for heredocs, + Sometimes you'd like to pass a block comment through to the generated + JavaScript. For example, when you need to embed a licensing header at + the top of a file. Block comments, which mirror the synax for heredocs, are preserved in the generated code.

<%= code_for('block_comment') %> @@ -806,8 +805,8 @@ coffee --print app/scripts/*.coffee > concatenation.js

- CoffeeScript includes a simple build system similar to - Make and + CoffeeScript includes a simple build system similar to + Make and Rake. Naturally, it's called Cake, and is used for the build and test tasks for the CoffeeScript language itself. Tasks are defined in a file named Cakefile, and diff --git a/documentation/js/aliases.js b/documentation/js/aliases.js index f5c56086..6f8a0800 100644 --- a/documentation/js/aliases.js +++ b/documentation/js/aliases.js @@ -1,17 +1,15 @@ -(function(){ - var volume, winner; - if (ignition === true) { - launch(); - } - if (band !== SpinalTap) { - volume = 10; - } - if (!(answer === false)) { - letTheWildRumpusBegin(); - } - car.speed < limit ? accelerate() : null; - if (47 === pick || 92 === pick || 13 === pick) { - winner = true; - } - print("My name is " + this.name); -})(); +var volume, winner; +if (ignition === true) { + launch(); +} +if (band !== SpinalTap) { + volume = 10; +} +if (!(answer === false)) { + letTheWildRumpusBegin(); +} +car.speed < limit ? accelerate() : null; +if (47 === pick || 92 === pick || 13 === pick) { + winner = true; +} +print("My name is " + this.name); \ No newline at end of file diff --git a/documentation/js/array_comprehensions.js b/documentation/js/array_comprehensions.js index d0dbb18c..29b68327 100644 --- a/documentation/js/array_comprehensions.js +++ b/documentation/js/array_comprehensions.js @@ -1,24 +1,22 @@ -(function(){ - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2; - lunch = (function() { - _a = []; _c = ['toast', 'cheese', 'wine']; - for (_b = 0, _d = _c.length; _b < _d; _b++) { - food = _c[_b]; - _a.push(eat(food)); - } - return _a; - })(); - _f = asteroids; - for (_e = 0, _g = _f.length; _e < _g; _e++) { - roid = _f[_e]; - _i = asteroids; - for (_h = 0, _j = _i.length; _h < _j; _h++) { - roid2 = _i[_h]; - if (roid !== roid2) { - if (roid.overlaps(roid2)) { - roid.explode(); - } +var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2; +lunch = (function() { + _a = []; _c = ['toast', 'cheese', 'wine']; + for (_b = 0, _d = _c.length; _b < _d; _b++) { + food = _c[_b]; + _a.push(eat(food)); + } + return _a; +})(); +_f = asteroids; +for (_e = 0, _g = _f.length; _e < _g; _e++) { + roid = _f[_e]; + _i = asteroids; + for (_h = 0, _j = _i.length; _h < _j; _h++) { + roid2 = _i[_h]; + if (roid !== roid2) { + if (roid.overlaps(roid2)) { + roid.explode(); } } } -})(); +} \ No newline at end of file diff --git a/documentation/js/assignment.js b/documentation/js/assignment.js index 5dbd5e24..106a6bff 100644 --- a/documentation/js/assignment.js +++ b/documentation/js/assignment.js @@ -1,5 +1,3 @@ -(function(){ - var difficulty, greeting; - greeting = "Hello CoffeeScript"; - difficulty = 0.5; -})(); +var difficulty, greeting; +greeting = "Hello CoffeeScript"; +difficulty = 0.5; \ No newline at end of file diff --git a/documentation/js/block_comment.js b/documentation/js/block_comment.js index c7c89d61..953e8b72 100644 --- a/documentation/js/block_comment.js +++ b/documentation/js/block_comment.js @@ -1,6 +1,4 @@ -(function(){ - /* - CoffeeScript Compiler v0.7.2 - Released under the MIT License - */ -})(); +/* +CoffeeScript Compiler v0.7.2 +Released under the MIT License +*/ \ No newline at end of file diff --git a/documentation/js/cake_tasks.js b/documentation/js/cake_tasks.js index d53e9e86..9086cde7 100644 --- a/documentation/js/cake_tasks.js +++ b/documentation/js/cake_tasks.js @@ -1,12 +1,10 @@ -(function(){ - var fs; - fs = require('fs'); - option('-o', '--output [DIR]', 'directory for compiled code'); - task('build:parser', 'rebuild the Jison parser', function() { - var code, dir; - require('jison'); - code = require('./lib/grammar').parser.generate(); - dir = options.output || 'lib'; - return fs.writeFile(("" + dir + "/parser.js"), code); - }); -})(); +var fs; +fs = require('fs'); +option('-o', '--output [DIR]', 'directory for compiled code'); +task('build:parser', 'rebuild the Jison parser', function() { + var code, dir; + require('jison'); + code = require('./lib/grammar').parser.generate(); + dir = options.output || 'lib'; + return fs.writeFile(("" + dir + "/parser.js"), code); +}); \ No newline at end of file diff --git a/documentation/js/classes.js b/documentation/js/classes.js index a4fccd95..463ce6ca 100644 --- a/documentation/js/classes.js +++ b/documentation/js/classes.js @@ -1,37 +1,36 @@ -(function(){ - var Animal, Horse, Snake, sam, tom; - var __extends = function(child, parent) { - var ctor = function(){ }; +var Animal, Horse, Snake, sam, tom; +var __extends = function(child, parent) { + var ctor = function(){}; ctor.prototype = parent.prototype; child.prototype = new ctor(); child.prototype.constructor = child; if (typeof parent.extended === "function") parent.extended(child); child.__superClass__ = parent.prototype; }; - Animal = function() {}; - Animal.prototype.move = function(meters) { - return alert(this.name + " moved " + meters + "m."); - }; - Snake = function(name) { - this.name = name; - return this; - }; - __extends(Snake, Animal); - Snake.prototype.move = function() { - alert("Slithering..."); - return Snake.__superClass__.move.call(this, 5); - }; - Horse = function(name) { - this.name = name; - return this; - }; - __extends(Horse, Animal); - Horse.prototype.move = function() { - alert("Galloping..."); - return Horse.__superClass__.move.call(this, 45); - }; - sam = new Snake("Sammy the Python"); - tom = new Horse("Tommy the Palomino"); - sam.move(); - tom.move(); -})(); +Animal = function(_a) { + this.name = _a; + return this; +}; +Animal.prototype.move = function(meters) { + return alert(this.name + " moved " + meters + "m."); +}; +Snake = function() { + return Animal.apply(this, arguments); +}; +__extends(Snake, Animal); +Snake.prototype.move = function() { + alert("Slithering..."); + return Snake.__superClass__.move.call(this, 5); +}; +Horse = function() { + return Animal.apply(this, arguments); +}; +__extends(Horse, Animal); +Horse.prototype.move = function() { + alert("Galloping..."); + return Horse.__superClass__.move.call(this, 45); +}; +sam = new Snake("Sammy the Python"); +tom = new Horse("Tommy the Palomino"); +sam.move(); +tom.move(); \ No newline at end of file diff --git a/documentation/js/comparisons.js b/documentation/js/comparisons.js index f7570581..e1ce0cc0 100644 --- a/documentation/js/comparisons.js +++ b/documentation/js/comparisons.js @@ -1,5 +1,3 @@ -(function(){ - var cholesterol, healthy; - cholesterol = 127; - healthy = (200 > cholesterol) && (cholesterol > 60); -})(); +var cholesterol, healthy; +cholesterol = 127; +healthy = (200 > cholesterol) && (cholesterol > 60); \ No newline at end of file diff --git a/documentation/js/conditionals.js b/documentation/js/conditionals.js index a16a20d6..d410542d 100644 --- a/documentation/js/conditionals.js +++ b/documentation/js/conditionals.js @@ -1,12 +1,12 @@ -(function(){ - var date, mood, options; - if (singing) { - mood = greatlyImproved; - } - if (happy && knowsIt) { - clapsHands(); - chaChaCha(); - } - date = friday ? sue : jill; - options = options || defaultOptions; -})(); +var date, mood, options; +if (singing) { + mood = greatlyImproved; +} +if (happy && knowsIt) { + clapsHands(); + chaChaCha(); +} else { + showIt(); +} +date = friday ? sue : jill; +options = options || defaults; \ No newline at end of file diff --git a/documentation/js/embedded.js b/documentation/js/embedded.js index 878acd86..3db2b0fb 100644 --- a/documentation/js/embedded.js +++ b/documentation/js/embedded.js @@ -1,6 +1,4 @@ -(function(){ - var hi; - hi = function() { +var hi; +hi = function() { return [document.title, "Hello JavaScript"].join(": "); -}; -})(); +}; \ No newline at end of file diff --git a/documentation/js/existence.js b/documentation/js/existence.js index f2c353d2..f48fdc59 100644 --- a/documentation/js/existence.js +++ b/documentation/js/existence.js @@ -1,7 +1,5 @@ -(function(){ - var solipsism, speed; - if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) { - solipsism = true; - } - speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; -})(); +var solipsism, speed; +if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) { + solipsism = true; +} +speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; \ No newline at end of file diff --git a/documentation/js/expressions.js b/documentation/js/expressions.js index 2e21f24a..9dd8947d 100644 --- a/documentation/js/expressions.js +++ b/documentation/js/expressions.js @@ -1,13 +1,11 @@ -(function(){ - var eldest, grade; - grade = function(student) { - if (student.excellentWork) { - return "A+"; - } else if (student.okayStuff) { - return student.triedHard ? "B" : "B-"; - } else { - return "C"; - } - }; - eldest = 24 > 21 ? "Liz" : "Ike"; -})(); +var eldest, grade; +grade = function(student) { + if (student.excellentWork) { + return "A+"; + } else if (student.okayStuff) { + return student.triedHard ? "B" : "B-"; + } else { + return "C"; + } +}; +eldest = 24 > 21 ? "Liz" : "Ike"; \ No newline at end of file diff --git a/documentation/js/expressions_assignment.js b/documentation/js/expressions_assignment.js index 1f6d7991..e75323d5 100644 --- a/documentation/js/expressions_assignment.js +++ b/documentation/js/expressions_assignment.js @@ -1,4 +1,2 @@ -(function(){ - var one, six, three, two; - six = (one = 1) + (two = 2) + (three = 3); -})(); +var one, six, three, two; +six = (one = 1) + (two = 2) + (three = 3); \ No newline at end of file diff --git a/documentation/js/expressions_comprehension.js b/documentation/js/expressions_comprehension.js index 5f15e5f4..39d2e660 100644 --- a/documentation/js/expressions_comprehension.js +++ b/documentation/js/expressions_comprehension.js @@ -1,12 +1,11 @@ -(function(){ - var _a, _b, globals, name; - var __hasProp = Object.prototype.hasOwnProperty; - globals = (function() { - _a = []; _b = window; - for (name in _b) { - if (!__hasProp.call(_b, name)) continue; - _a.push(name); - } - return _a; - })().slice(0, 10); -})(); +var _a, _b, _c, globals, name; +var __hasProp = Object.prototype.hasOwnProperty; +globals = (function() { + _b = []; _c = window; + for (name in _c) { + if (!__hasProp.call(_c, name)) continue; + _a = _c[name]; + _b.push(name); + } + return _b; +})().slice(0, 10); \ No newline at end of file diff --git a/documentation/js/expressions_try.js b/documentation/js/expressions_try.js index a6bb2bca..19a9506c 100644 --- a/documentation/js/expressions_try.js +++ b/documentation/js/expressions_try.js @@ -1,9 +1,7 @@ -(function(){ - alert((function() { - try { - return nonexistent / undefined; - } catch (error) { - return "And the error is ... " + error; - } - })()); -})(); +alert((function() { + try { + return nonexistent / undefined; + } catch (error) { + return "And the error is ... " + error; + } +})()); \ No newline at end of file diff --git a/documentation/js/fat_arrow.js b/documentation/js/fat_arrow.js index 0481518f..41744ed5 100644 --- a/documentation/js/fat_arrow.js +++ b/documentation/js/fat_arrow.js @@ -1,15 +1,11 @@ -(function(){ - var Account; - Account = function(customer, cart) { - this.customer = customer; - this.cart = cart; - return $('.shopping_cart').bind('click', (function(__this) { - var __func = function(event) { - return this.customer.purchase(this.cart); - }; - return (function() { - return __func.apply(__this, arguments); - }); - })(this)); +var Account; +var __bind = function(func, context) { + return function(){ return func.apply(context, arguments); }; }; -})(); +Account = function(customer, cart) { + this.customer = customer; + this.cart = cart; + return $('.shopping_cart').bind('click', __bind(function(event) { + return this.customer.purchase(this.cart); + }, this)); +}; \ No newline at end of file diff --git a/documentation/js/functions.js b/documentation/js/functions.js index 2678a166..ec38bc78 100644 --- a/documentation/js/functions.js +++ b/documentation/js/functions.js @@ -1,9 +1,7 @@ -(function(){ - var cube, square; - square = function(x) { - return x * x; - }; - cube = function(x) { - return square(x) * x; - }; -})(); +var cube, square; +square = function(x) { + return x * x; +}; +cube = function(x) { + return square(x) * x; +}; \ No newline at end of file diff --git a/documentation/js/heredocs.js b/documentation/js/heredocs.js index bc9f2d6b..0cbcb2aa 100644 --- a/documentation/js/heredocs.js +++ b/documentation/js/heredocs.js @@ -1,4 +1,2 @@ -(function(){ - var html; - html = '\n cup of coffeescript\n'; -})(); +var html; +html = '\n cup of coffeescript\n'; \ No newline at end of file diff --git a/documentation/js/interpolation.js b/documentation/js/interpolation.js index 369d5c8a..6b4e124a 100644 --- a/documentation/js/interpolation.js +++ b/documentation/js/interpolation.js @@ -1,5 +1,3 @@ -(function(){ - var author, quote; - author = "Wittgenstein"; - quote = ("A picture is a fact. -- " + author); -})(); +var author, quote; +author = "Wittgenstein"; +quote = ("A picture is a fact. -- " + author); \ No newline at end of file diff --git a/documentation/js/interpolation_expression.js b/documentation/js/interpolation_expression.js index fe7e5239..9651e488 100644 --- a/documentation/js/interpolation_expression.js +++ b/documentation/js/interpolation_expression.js @@ -1,6 +1,4 @@ -(function(){ - var dates, sentence, sep; - sentence = ("" + (22 / 7) + " is a decent approximation of π"); - sep = "[.\\/\\- ]"; - dates = (new RegExp(("\\d+" + sep + "\\d+" + sep + "\\d+"), "g")); -})(); +var dates, sentence, sep; +sentence = ("" + (22 / 7) + " is a decent approximation of π"); +sep = "[.\\/\\- ]"; +dates = /\d+$sep\d+$sep\d+/g; \ No newline at end of file diff --git a/documentation/js/multiple_return_values.js b/documentation/js/multiple_return_values.js index 3345d42e..f46b21dc 100644 --- a/documentation/js/multiple_return_values.js +++ b/documentation/js/multiple_return_values.js @@ -1,10 +1,8 @@ -(function(){ - var _a, city, forecast, temp, weatherReport; - weatherReport = function(location) { - return [location, 72, "Mostly Sunny"]; - }; - _a = weatherReport("Berkeley, CA"); - city = _a[0]; - temp = _a[1]; - forecast = _a[2]; -})(); +var _a, city, forecast, temp, weatherReport; +weatherReport = function(location) { + return [location, 72, "Mostly Sunny"]; +}; +_a = weatherReport("Berkeley, CA"); +city = _a[0]; +temp = _a[1]; +forecast = _a[2]; \ No newline at end of file diff --git a/documentation/js/object_comprehensions.js b/documentation/js/object_comprehensions.js index bd637117..b5505f3e 100644 --- a/documentation/js/object_comprehensions.js +++ b/documentation/js/object_comprehensions.js @@ -1,18 +1,16 @@ -(function(){ - var _a, _b, age, ages, child, yearsOld; - var __hasProp = Object.prototype.hasOwnProperty; - yearsOld = { - max: 10, - ida: 9, - tim: 11 - }; - ages = (function() { - _a = []; _b = yearsOld; - for (child in _b) { - if (!__hasProp.call(_b, child)) continue; - age = _b[child]; - _a.push(child + " is " + age); - } - return _a; - })(); -})(); +var _a, _b, age, ages, child, yearsOld; +var __hasProp = Object.prototype.hasOwnProperty; +yearsOld = { + max: 10, + ida: 9, + tim: 11 +}; +ages = (function() { + _a = []; _b = yearsOld; + for (child in _b) { + if (!__hasProp.call(_b, child)) continue; + age = _b[child]; + _a.push(child + " is " + age); + } + return _a; +})(); \ No newline at end of file diff --git a/documentation/js/object_extraction.js b/documentation/js/object_extraction.js index eee7e448..b935daa4 100644 --- a/documentation/js/object_extraction.js +++ b/documentation/js/object_extraction.js @@ -1,17 +1,15 @@ -(function(){ - var _a, _b, _c, city, futurists, name, street; - futurists = { - sculptor: "Umberto Boccioni", - painter: "Vladimir Burliuk", - poet: { - name: "F.T. Marinetti", - address: ["Via Roma 42R", "Bellagio, Italy 22021"] - } - }; - _a = futurists; - _b = _a.poet; - name = _b.name; - _c = _b.address; - street = _c[0]; - city = _c[1]; -})(); +var _a, _b, _c, city, futurists, name, street; +futurists = { + sculptor: "Umberto Boccioni", + painter: "Vladimir Burliuk", + poet: { + name: "F.T. Marinetti", + address: ["Via Roma 42R", "Bellagio, Italy 22021"] + } +}; +_a = futurists; +_b = _a.poet; +name = _b.name; +_c = _b.address; +street = _c[0]; +city = _c[1]; \ No newline at end of file diff --git a/documentation/js/objects_and_arrays.js b/documentation/js/objects_and_arrays.js index 2906a153..66cc9011 100644 --- a/documentation/js/objects_and_arrays.js +++ b/documentation/js/objects_and_arrays.js @@ -1,10 +1,12 @@ -(function(){ - var ages, matrix, song; - song = ["do", "re", "mi", "fa", "so"]; - ages = { - max: 10, - ida: 9, - tim: 11 - }; - matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0]; -})(); +var ages, matrix, singers, song; +song = ["do", "re", "mi", "fa", "so"]; +singers = { + Jagger: 'Rock', + Elvis: 'Roll' +}; +ages = { + max: 10, + ida: 9, + tim: 11 +}; +matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0]; \ No newline at end of file diff --git a/documentation/js/objects_reserved.js b/documentation/js/objects_reserved.js index 57552aff..6fd6fea2 100644 --- a/documentation/js/objects_reserved.js +++ b/documentation/js/objects_reserved.js @@ -1,5 +1,3 @@ -(function(){ - $('.account').css({ - 'class': 'active' - }); -})(); +$('.account').css({ + 'class': 'active' +}); \ No newline at end of file diff --git a/documentation/js/overview.js b/documentation/js/overview.js index dea69bcc..cfb3aba7 100644 --- a/documentation/js/overview.js +++ b/documentation/js/overview.js @@ -1,37 +1,34 @@ -(function(){ - var _a, _b, _c, _d, cubes, list, math, num, number, opposite, race, square; - var __slice = Array.prototype.slice; - number = 42; - opposite = true; - if (opposite) { - number = -42; +var _a, _b, _c, _d, cubes, list, math, num, number, opposite, race, square; +var __slice = Array.prototype.slice; +number = 42; +opposite = true; +if (opposite) { + number = -42; +} +square = function(x) { + return x * x; +}; +list = [1, 2, 3, 4, 5]; +math = { + root: Math.sqrt, + square: square, + cube: function(x) { + return x * square(x); } - square = function(x) { - return x * x; - }; - list = [1, 2, 3, 4, 5]; - math = { - root: Math.sqrt, - square: square, - cube: function(x) { - return x * square(x); - } - }; - race = function(winner) { - var runners; - var _a = arguments.length, _b = _a >= 2; - runners = __slice.call(arguments, 1, _a - 0); - return print(winner, runners); - }; - if (typeof elvis !== "undefined" && elvis !== null) { - alert("I knew it!"); +}; +race = function(winner) { + var runners; + runners = __slice.call(arguments, 1); + return print(winner, runners); +}; +if (typeof elvis !== "undefined" && elvis !== null) { + alert("I knew it!"); +} +cubes = (function() { + _a = []; _c = list; + for (_b = 0, _d = _c.length; _b < _d; _b++) { + num = _c[_b]; + _a.push(math.cube(num)); } - cubes = (function() { - _a = []; _c = list; - for (_b = 0, _d = _c.length; _b < _d; _b++) { - num = _c[_b]; - _a.push(math.cube(num)); - } - return _a; - })(); -})(); + return _a; +})(); \ No newline at end of file diff --git a/documentation/js/parallel_assignment.js b/documentation/js/parallel_assignment.js index c231e3f3..f1f7b923 100644 --- a/documentation/js/parallel_assignment.js +++ b/documentation/js/parallel_assignment.js @@ -1,8 +1,6 @@ -(function(){ - var _a, theBait, theSwitch; - theBait = 1000; - theSwitch = 0; - _a = [theSwitch, theBait]; - theBait = _a[0]; - theSwitch = _a[1]; -})(); +var _a, theBait, theSwitch; +theBait = 1000; +theSwitch = 0; +_a = [theSwitch, theBait]; +theBait = _a[0]; +theSwitch = _a[1]; \ No newline at end of file diff --git a/documentation/js/patterns_and_splats.js b/documentation/js/patterns_and_splats.js index 7aa30dc5..dfe1081f 100644 --- a/documentation/js/patterns_and_splats.js +++ b/documentation/js/patterns_and_splats.js @@ -1,9 +1,7 @@ -(function(){ - var _a, close, contents, open, tag; - var __slice = Array.prototype.slice; - tag = ""; - _a = tag.split(""); - open = _a[0]; - contents = __slice.call(_a, 1, _a.length - 1); - close = _a[_a.length - 1]; -})(); +var _a, close, contents, open, tag; +var __slice = Array.prototype.slice; +tag = ""; +_a = tag.split(""); +open = _a[0]; +contents = __slice.call(_a, 1, _a.length - 1); +close = _a[_a.length - 1]; \ No newline at end of file diff --git a/documentation/js/prototypes.js b/documentation/js/prototypes.js index 628c24de..418bc10f 100644 --- a/documentation/js/prototypes.js +++ b/documentation/js/prototypes.js @@ -1,5 +1,3 @@ -(function(){ - String.prototype.dasherize = function() { - return this.replace(/_/g, "-"); - }; -})(); +String.prototype.dasherize = function() { + return this.replace(/_/g, "-"); +}; \ No newline at end of file diff --git a/documentation/js/range_comprehensions.js b/documentation/js/range_comprehensions.js index e7b2cc30..fa3f1f1d 100644 --- a/documentation/js/range_comprehensions.js +++ b/documentation/js/range_comprehensions.js @@ -1,21 +1,19 @@ -(function(){ - var _a, countdown, deliverEggs, num; - countdown = (function() { - _a = []; - for (num = 10; num >= 1; num--) { - _a.push(num); - } - return _a; - })(); - deliverEggs = function() { - var _b, _c, dozen, i; - _b = []; _c = eggs.length; - for (i = 0; (0 <= _c ? i < _c : i > _c); i += 12) { - _b.push((function() { - dozen = eggs.slice(i, i + 12); - return deliver(new eggCarton(dozen)); - })()); - } - return _b; - }; +var _a, countdown, deliverEggs, num; +countdown = (function() { + _a = []; + for (num = 10; num >= 1; num--) { + _a.push(num); + } + return _a; })(); +deliverEggs = function() { + var _b, _c, dozen, i; + _b = []; _c = eggs.length; + for (i = 0; (0 <= _c ? i < _c : i > _c); i += 12) { + _b.push((function() { + dozen = eggs.slice(i, i + 12); + return deliver(new eggCarton(dozen)); + })()); + } + return _b; +}; \ No newline at end of file diff --git a/documentation/js/scope.js b/documentation/js/scope.js index 6af29afd..478badf0 100644 --- a/documentation/js/scope.js +++ b/documentation/js/scope.js @@ -1,11 +1,8 @@ -(function(){ - var changeNumbers, inner, outer; - outer = 1; - changeNumbers = function() { - var inner; - inner = -1; - outer = 10; - return outer; - }; - inner = changeNumbers(); -})(); +var changeNumbers, inner, outer; +outer = 1; +changeNumbers = function() { + var inner; + inner = -1; + return (outer = 10); +}; +inner = changeNumbers(); \ No newline at end of file diff --git a/documentation/js/slices.js b/documentation/js/slices.js index 1fb3a229..064c5025 100644 --- a/documentation/js/slices.js +++ b/documentation/js/slices.js @@ -1,6 +1,4 @@ -(function(){ - var copy, numbers, threeToSix; - numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; - threeToSix = numbers.slice(3, 6 + 1); - copy = numbers.slice(0, numbers.length); -})(); +var copy, numbers, threeToSix; +numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +threeToSix = numbers.slice(3, 6 + 1); +copy = numbers.slice(0, numbers.length); \ No newline at end of file diff --git a/documentation/js/soaks.js b/documentation/js/soaks.js index 7baf2ce8..f24803da 100644 --- a/documentation/js/soaks.js +++ b/documentation/js/soaks.js @@ -1,4 +1,2 @@ -(function(){ - var _a, _b; - (_b = (typeof (_a = (lottery.drawWinner())) === "undefined" || _a == undefined ? undefined : _a.address)) == undefined ? undefined : _b.zipcode; -})(); +var _a, _b; +(_b = (typeof (_a = (lottery.drawWinner())) === "undefined" || _a == undefined ? undefined : _a.address)) == undefined ? undefined : _b.zipcode; \ No newline at end of file diff --git a/documentation/js/splats.js b/documentation/js/splats.js index 7bc025ec..aa04e1c4 100644 --- a/documentation/js/splats.js +++ b/documentation/js/splats.js @@ -1,18 +1,15 @@ -(function(){ - var awardMedals, contenders, gold, rest, silver; - var __slice = Array.prototype.slice; - gold = (silver = (rest = "unknown")); - awardMedals = function(first, second) { - var _a = arguments.length, _b = _a >= 3; - rest = __slice.call(arguments, 2, _a - 0); - gold = first; - silver = second; - rest = rest; - return rest; - }; - contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"]; - awardMedals.apply(this, contenders); - alert("Gold: " + gold); - alert("Silver: " + silver); - alert("The Field: " + rest); -})(); +var awardMedals, contenders, gold, rest, silver; +var __slice = Array.prototype.slice; +gold = (silver = (rest = "unknown")); +awardMedals = function(first, second) { + var others; + others = __slice.call(arguments, 2); + gold = first; + silver = second; + return (rest = others); +}; +contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"]; +awardMedals.apply(this, contenders); +alert("Gold: " + gold); +alert("Silver: " + silver); +alert("The Field: " + rest); \ No newline at end of file diff --git a/documentation/js/splices.js b/documentation/js/splices.js index 9af56404..cd60fe70 100644 --- a/documentation/js/splices.js +++ b/documentation/js/splices.js @@ -1,5 +1,3 @@ -(function(){ - var numbers; - numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; - numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6])); -})(); +var numbers; +numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6])); \ No newline at end of file diff --git a/documentation/js/strings.js b/documentation/js/strings.js index 5bc11cd6..a8d333cb 100644 --- a/documentation/js/strings.js +++ b/documentation/js/strings.js @@ -1,9 +1,7 @@ -(function(){ - var mobyDick; - mobyDick = "Call me Ishmael. Some years ago -- \ +var mobyDick; +mobyDick = "Call me Ishmael. Some years ago -- \ never mind how long precisely -- having little \ or no money in my purse, and nothing particular \ to interest me on shore, I thought I would sail \ about a little and see the watery part of the \ -world..."; -})(); +world..."; \ No newline at end of file diff --git a/documentation/js/switch.js b/documentation/js/switch.js index 7b34e3f8..3334b6b1 100644 --- a/documentation/js/switch.js +++ b/documentation/js/switch.js @@ -1,18 +1,16 @@ -(function(){ - if (day === "Mon") { - goToWork(); - } else if (day === "Tue") { - goToThePark(); - } else if (day === "Thu") { - goIceFishing(); - } else if (day === "Fri" || day === "Sat") { - if (day === bingoDay) { - goToBingo(); - goDancing(); - } - } else if (day === "Sun") { - goToChurch(); - } else { - goToWork(); +if (day === "Mon") { + goToWork(); +} else if (day === "Tue") { + goToThePark(); +} else if (day === "Thu") { + goIceFishing(); +} else if (day === "Fri" || day === "Sat") { + if (day === bingoDay) { + goToBingo(); + goDancing(); } -})(); +} else if (day === "Sun") { + goToChurch(); +} else { + goToWork(); +} \ No newline at end of file diff --git a/documentation/js/try.js b/documentation/js/try.js index ad4f79cb..97b089fb 100644 --- a/documentation/js/try.js +++ b/documentation/js/try.js @@ -1,10 +1,8 @@ -(function(){ - try { - allHellBreaksLoose(); - catsAndDogsLivingTogether(); - } catch (error) { - print(error); - } finally { - cleanUp(); - } -})(); +try { + allHellBreaksLoose(); + catsAndDogsLivingTogether(); +} catch (error) { + print(error); +} finally { + cleanUp(); +} \ No newline at end of file diff --git a/documentation/js/while.js b/documentation/js/while.js index 0a9d2580..ffb48f35 100644 --- a/documentation/js/while.js +++ b/documentation/js/while.js @@ -1,20 +1,18 @@ -(function(){ - var _a, lyrics, num; - if (this.studyingEconomics) { - while (supply > demand) { - buy(); - } - while (!(supply > demand)) { - sell(); - } +var _a, lyrics, num; +if (this.studyingEconomics) { + while (supply > demand) { + buy(); } - num = 6; - lyrics = (function() { - _a = []; - while (num -= 1) { - _a.push(num + " little monkeys, jumping on the bed. \ + while (!(supply > demand)) { + sell(); + } +} +num = 6; +lyrics = (function() { + _a = []; + while (num -= 1) { + _a.push(num + " little monkeys, jumping on the bed. \ One fell out and bumped his head."); - } - return _a; - })(); -})(); + } + return _a; +})(); \ No newline at end of file diff --git a/index.html b/index.html index 14ae5c9f..a8ad99cc 100644 --- a/index.html +++ b/index.html @@ -126,34 +126,33 @@ alert reverse '.eeffoC yrT'

CoffeeScript on the left, compiled JavaScript output on the right.

# Assignment:
-number: 42
-opposite: true
+number   = 42
+opposite = true
 
 # Conditions:
-number: -42 if opposite
+number = -42 if opposite
 
 # Functions:
-square: (x) -> x * x
+square = (x) -> x * x
 
 # Arrays:
-list: [1, 2, 3, 4, 5]
+list = [1, 2, 3, 4, 5]
 
 # Objects:
-math: {
+math =
   root:   Math.sqrt
   square: square
   cube:   (x) -> x * square x
-}
 
 # Splats:
-race: (winner, runners...) ->
+race = (winner, runners...) ->
   print winner, runners
 
 # Existence:
 alert "I knew it!" if elvis?
 
 # Array comprehensions:
-cubes: math.cube num for num in list
+cubes = math.cube num for num in list
 
var _a, _b, _c, _d, cubes, list, math, num, number, opposite, race, square;
 var __slice = Array.prototype.slice;
 number = 42;
@@ -174,8 +173,7 @@ math = {
 };
 race = function(winner) {
   var runners;
-  var _a = arguments.length, _b = _a >= 2;
-  runners = __slice.call(arguments, 1, _a - 0);
+  runners = __slice.call(arguments, 1);
   return print(winner, runners);
 };
 if (typeof elvis !== "undefined" && elvis !== null) {
@@ -209,8 +207,7 @@ math = {
 };
 race = function(winner) {
   var runners;
-  var _a = arguments.length, _b = _a >= 2;
-  runners = __slice.call(arguments, 1, _a - 0);
+  runners = __slice.call(arguments, 1);
   return print(winner, runners);
 };
 if (typeof elvis !== "undefined" && elvis !== null) {
@@ -223,8 +220,7 @@ cubes = (function() {
     _a.push(math.cube(num));
   }
   return _a;
-})();
-;alert(cubes);'>run: cubes
+})();;alert(cubes);'>run: cubes

For a longer CoffeeScript example, check out @@ -441,8 +437,8 @@ coffee --print app/scripts/*.coffee > concatenation.js Functions are defined by a list of parameters, an arrow, and the function body. The empty function looks like this: ->

-
square: (x) -> x * x
-cube:   (x) -> square(x) * x
+    
square = (x) -> x * x
+cube   = (x) -> square(x) * x
 
var cube, square;
 square = function(x) {
   return x * x;
@@ -456,8 +452,7 @@ square = function(x) {
 };
 cube = function(x) {
   return square(x) * x;
-};
-;alert(cube(5));'>run: cube(5)
+};;alert(cube(5));'>run: cube(5)

If you'd like to assign a function literal to a variable, but not have it be named, just wrap the function definition in parentheses: @@ -472,15 +467,14 @@ cube = function(x) { mathy things. While colons are preferred, the two may be used interchangeably, even within object literals.

-
greeting: "Hello CoffeeScript"
-difficulty: 0.5
+    
greeting   = "Hello CoffeeScript"
+difficulty = 0.5
 
var difficulty, greeting;
 greeting = "Hello CoffeeScript";
 difficulty = 0.5;
 

+difficulty = 0.5;;alert(greeting);'>run: greeting

All declaration of new variables is pushed up to the top of the nearest lexical scope, so that assignment may always be performed within expressions. @@ -495,42 +489,50 @@ difficulty = 0.5; assigning local variables, and can be moved around freely. Feel free to mix and match the two styles.

-
song: ["do", "re", "mi", "fa", "so"]
+    
song = ["do", "re", "mi", "fa", "so"]
 
-ages: {
+singers = {Jagger: 'Rock', Elvis: 'Roll'}
+
+ages =
   max: 10
   ida: 9
   tim: 11
-}
 
-matrix: [
+matrix = [
   1, 0, 1
   0, 0, 1
   1, 1, 0
 ]
-
var ages, matrix, song;
+
var ages, matrix, singers, song;
 song = ["do", "re", "mi", "fa", "so"];
+singers = {
+  Jagger: 'Rock',
+  Elvis: 'Roll'
+};
 ages = {
   max: 10,
   ida: 9,
   tim: 11
 };
 matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
-

+matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];;alert(song.join(","));'>run: song.join(",")

In JavaScript, you can't use reserved words, like class, as properties of an object, without quoting them as strings. CoffeeScript notices and quotes them for you, so you don't have to worry about it (say, when using jQuery).

-
$('.account').css {class: 'active'}
+    
$('.account').css class: 'active'
 
$('.account').css({
   'class': 'active'
 });
@@ -543,18 +545,17 @@ matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
       are properly declared within lexical scope — you never need to write
       var yourself.
     

-
outer: 1
-changeNumbers: ->
-  inner: -1
-  outer: 10
-inner: changeNumbers()
+    
outer = 1
+changeNumbers = ->
+  inner = -1
+  outer = 10
+inner = changeNumbers()
 
var changeNumbers, inner, outer;
 outer = 1;
 changeNumbers = function() {
   var inner;
   inner = -1;
-  outer = 10;
-  return outer;
+  return (outer = 10);
 };
 inner = changeNumbers();
 

+inner = changeNumbers();;alert(inner);'>run: inner

Notice how the all of the variable declarations have been pushed up to the top of the closest scope, the first time they appear. @@ -611,15 +610,17 @@ inner = changeNumbers(); is no explicit ternary statement in CoffeeScript — you simply use a regular if statement inline.

-
mood: greatlyImproved if singing
+    
mood = greatlyImproved if singing
 
 if happy and knowsIt
   clapsHands()
   chaChaCha()
+else
+  showIt()
 
-date: if friday then sue else jill
+date = if friday then sue else jill
 
-options: or defaultOptions
+options = or defaults
 
var date, mood, options;
 if (singing) {
   mood = greatlyImproved;
@@ -627,9 +628,11 @@ options: or defaultOpt
 if (happy && knowsIt) {
   clapsHands();
   chaChaCha();
+} else {
+  showIt();
 }
 date = friday ? sue : jill;
-options = options || defaultOptions;
+options = options || defaults;
 

You can assign a variable to a half-expression to perform an operation @@ -675,13 +678,13 @@ options = options || d

launch() if ignition is on
 
-volume: 10 if band isnt SpinalTap
+volume = 10 if band isnt SpinalTap
 
 letTheWildRumpusBegin() unless answer is no
 
 if car.speed < limit then accelerate()
 
-winner: yes if pick in [47, 92, 13]
+winner = yes if pick in [47, 92, 13]
 
 print "My name is " + @name
 
var volume, winner;
@@ -709,14 +712,14 @@ car.speed < limit ? accelerate() : gold: silver: rest: "unknown"
+    
gold = silver = rest = "unknown"
 
-awardMedals: (first, second, rest...) ->
-  gold:   first
-  silver: second
-  rest:   rest
+awardMedals = (first, second, others...) ->
+  gold   = first
+  silver = second
+  rest   = others
 
-contenders: [
+contenders = [
   "Michael Phelps"
   "Liu Xiang"
   "Yao Ming"
@@ -738,12 +741,11 @@ alert "The Field: var __slice = Array.prototype.slice;
 gold = (silver = (rest = "unknown"));
 awardMedals = function(first, second) {
-  var _a = arguments.length, _b = _a >= 3;
-  rest = __slice.call(arguments, 2, _a - 0);
+  var others;
+  others = __slice.call(arguments, 2);
   gold = first;
   silver = second;
-  rest = rest;
-  return rest;
+  return (rest = others);
 };
 contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
 awardMedals.apply(this, contenders);
@@ -754,19 +756,17 @@ awardMedals.apply(th
 var __slice = Array.prototype.slice;
 gold = (silver = (rest = "unknown"));
 awardMedals = function(first, second) {
-  var _a = arguments.length, _b = _a >= 3;
-  rest = __slice.call(arguments, 2, _a - 0);
+  var others;
+  others = __slice.call(arguments, 2);
   gold = first;
   silver = second;
-  rest = rest;
-  return rest;
+  return (rest = others);
 };
 contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
 awardMedals.apply(this, contenders);
 alert("Gold: " + gold);
 alert("Silver: " + silver);
-alert("The Field: " + rest);
-;'>run
+alert("The Field: " + rest);;'>run

@@ -782,8 +782,8 @@ alert("The Field: " + rest); sell() until supply > demand # Nursery Rhyme -num: 6 -lyrics: while num: - 1 +num = 6 +lyrics = while num -= 1 num + " little monkeys, jumping on the bed. One fell out and bumped his head."

var _a, lyrics, num;
@@ -821,8 +821,7 @@ lyrics = (function() {
 One fell out and bumped his head.");
   }
   return _a;
-})();
-;alert(lyrics.join("\n"));'>run: lyrics.join("\n")
+})();;alert(lyrics.join("\n"));'>run: lyrics.join("\n")

For readability, the until keyword is equivalent to while not, and the loop keyword is equivalent to while true. @@ -843,7 +842,7 @@ One fell out and bumped his head."); would use a loop, each/forEach, map, or select/filter.

# Eat lunch.
-lunch: eat food for food in ['toast', 'cheese', 'wine']
+lunch = eat food for food in ['toast', 'cheese', 'wine']
 
 # Naive collision detection.
 for roid in asteroids
@@ -877,12 +876,12 @@ _f = asteroids;
       in fixed-size increments, you can use a range to specify the start and
       end of your comprehension.
     

-
countdown: num for num in [10..1]
+    
countdown = num for num in [10..1]
 
-deliverEggs: ->
+deliverEggs = ->
   for i in [0...eggs.length] by 12
-    dozen: eggs[i...i+12]
-    deliver new eggCarton(dozen)
+    dozen = eggs[i...i+12]
+    deliver new eggCarton dozen
 
var _a, countdown, deliverEggs, num;
 countdown = (function() {
   _a = [];
@@ -920,16 +919,15 @@ deliverEggs = function() {
     })());
   }
   return _b;
-};
-;alert(countdown);'>run: countdown
+};;alert(countdown);'>run: countdown

Comprehensions can also be used to iterate over the keys and values in an object. Use of to signal comprehension over the properties of an object instead of the values in an array.

-
yearsOld: {max: 10, ida: 9, tim: 11}
+    
yearsOld = max: 10, ida: 9, tim: 11
 
-ages: for child, age of yearsOld
+ages = for child, age of yearsOld
   child + " is " + age
 
var _a, _b, age, ages, child, yearsOld;
 var __hasProp = Object.prototype.hasOwnProperty;
@@ -962,8 +960,7 @@ ages = (function() {
     _a.push(child + " is " + age);
   }
   return _a;
-})();
-;alert(ages.join(", "));'>run: ages.join(", ")
+})();;alert(ages.join(", "));'>run: ages.join(", ")

@@ -975,11 +972,11 @@ ages = (function() { the slice, and the second is the index of the last one. Three dots signify a range that excludes the end.

-
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+    
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
-threeToSix: numbers[3..6]
+threeToSix = numbers[3..6]
 
-copy: numbers[0...numbers.length]
+copy = numbers[0...numbers.length]
 
 
var copy, numbers, threeToSix;
 numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@@ -988,15 +985,14 @@ copy = numbers.slice<
 

+copy = numbers.slice(0, numbers.length);;alert(copy);'>run: copy

The same syntax can be used with assignment to replace a segment of an array with new values (to splice it).

-
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+    
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
-numbers[3..6]: [-3, -4, -5, -6]
+numbers[3..6] = [-3, -4, -5, -6]
 
 
 
var numbers;
@@ -1004,8 +1000,7 @@ numbers = [0, apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));
 

+numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));;alert(numbers);'>run: numbers

@@ -1017,7 +1012,7 @@ numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6])); pushed down into each possible branch of execution, in the function below.

-
grade: (student) ->
+    
grade = (student) ->
   if student.excellentWork
     "A+"
   else if student.okayStuff
@@ -1025,7 +1020,7 @@ numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));
   else
     "C"
 
-eldest: if 24 > 21 then "Liz" else "Ike"
+eldest = if 24 > 21 then "Liz" else "Ike"
 
var eldest, grade;
 grade = function(student) {
   if (student.excellentWork) {
@@ -1047,8 +1042,7 @@ grade = function(student) {
     return "C";
   }
 };
-eldest = 24 > 21 ? "Liz" : "Ike";
-;alert(eldest);'>run: eldest
+eldest = 24 > 21 ? "Liz" : "Ike";;alert(eldest);'>run: eldest

Even though functions will always return their final value, it's both possible and encouraged to return early from a function body writing out the explicit @@ -1058,12 +1052,11 @@ eldest = 24 > 21 ? "Liz" : "Ike"; Because variable declarations occur at the top of scope, assignment can be used within expressions, even for variables that haven't been seen before:

-
six: (one: 1) + (two: 2) + (three: 3)
+    
six = (one = 1) + (two = 2) + (three = 3)
 
var one, six, three, two;
 six = (one = 1) + (two = 2) + (three = 3);
 

+six = (one = 1) + (two = 2) + (three = 3);;alert(six);'>run: six

Things that would otherwise be statements in JavaScript, when used as part of an expression in CoffeeScript, are converted into expressions @@ -1072,28 +1065,29 @@ six = (one = 1) + (two = 2) + (three = 3);

# The first ten global properties.
 
-globals: (name for name of window)[0...10]
-
var _a, _b, globals, name;
+globals = (name for name of window)[0...10]
+
var _a, _b, _c, globals, name;
 var __hasProp = Object.prototype.hasOwnProperty;
 globals = (function() {
-  _a = []; _b = window;
-  for (name in _b) {
-    if (!__hasProp.call(_b, name)) continue;
-    _a.push(name);
+  _b = []; _c = window;
+  for (name in _c) {
+    if (!__hasProp.call(_c, name)) continue;
+    _a = _c[name];
+    _b.push(name);
   }
-  return _a;
+  return _b;
 })().slice(0, 10);
-

+ return _b; +})().slice(0, 10);;alert(globals);'>run: globals

As well as silly things, like passing a try/catch statement directly into a function call: @@ -1117,8 +1111,7 @@ globals = (function() { } catch (error) { return "And the error is ... " + error; } -})()); -;'>run

+})());;'>run

There are a handful of statements in JavaScript that can't be meaningfully converted into expressions, namely break, continue, @@ -1139,7 +1132,7 @@ globals = (function() { It can also be used for safer conditional assignment than ||= provides, for cases where you may be handling numbers or strings.

-
solipsism: true if mind? and not world?
+    
solipsism = true if mind? and not world?
 
 speed ?= 140
 
@@ -1156,8 +1149,7 @@ speed = (typeof speed
 if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
   solipsism = true;
 }
-speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;
-;alert(speed);'>run: speed
+speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;;alert(speed);'>run: speed

The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead @@ -1199,27 +1191,23 @@ speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; in a single assignable expression.

class Animal
+  constructor: (@name) ->
+
   move: (meters) ->
     alert @name + " moved " + meters + "m."
 
 class Snake extends Animal
-  constructor: (name) ->
-    @name: name
-
   move: ->
     alert "Slithering..."
     super 5
 
 class Horse extends Animal
-  constructor: (name) ->
-    @name: name
-
   move: ->
     alert "Galloping..."
     super 45
 
-sam: new Snake "Sammy the Python"
-tom: new Horse "Tommy the Palomino"
+sam = new Snake "Sammy the Python"
+tom = new Horse "Tommy the Palomino"
 
 sam.move()
 tom.move()
@@ -1229,29 +1217,30 @@ tom.move()
 
 
var Animal, Horse, Snake, sam, tom;
 var __extends = function(child, parent) {
-  var ctor = function(){ };
-  ctor.prototype = parent.prototype;
-  child.prototype = new ctor();
-  child.prototype.constructor = child;
-  if (typeof parent.extended === "function") parent.extended(child);
-  child.__superClass__ = parent.prototype;
+    var ctor = function(){};
+    ctor.prototype = parent.prototype;
+    child.prototype = new ctor();
+    child.prototype.constructor = child;
+    if (typeof parent.extended === "function") parent.extended(child);
+    child.__superClass__ = parent.prototype;
+  };
+Animal = function(_a) {
+  this.name = _a;
+  return this;
 };
-Animal = function() {};
 Animal.prototype.move = function(meters) {
   return alert(this.name + " moved " + meters + "m.");
 };
-Snake = function(name) {
-  this.name = name;
-  return this;
+Snake = function() {
+  return Animal.apply(this, arguments);
 };
 __extends(Snake, Animal);
 Snake.prototype.move = function() {
   alert("Slithering...");
   return Snake.__superClass__.move.call(this, 5);
 };
-Horse = function(name) {
-  this.name = name;
-  return this;
+Horse = function() {
+  return Animal.apply(this, arguments);
 };
 __extends(Horse, Animal);
 Horse.prototype.move = function() {
@@ -1264,29 +1253,30 @@ sam.move();
 tom.move();
 

+tom.move();;'>run

If structuring your prototypes classically isn't your cup of tea, CoffeeScript provides a couple of lower-level conveniences. The extends operator @@ -1305,15 +1294,14 @@ tom.move(); quick access to an object's prototype, and super() is converted into a call against the immediate ancestor's method of the same name.

-
String::dasherize: ->
-  this.replace(/_/g, "-")
+    
String::dasherize = ->
+  this.replace /_/g, "-"
 
String.prototype.dasherize = function() {
   return this.replace(/_/g, "-");
 };
 

+};;alert("one_two".dasherize());'>run: "one_two".dasherize()

Finally, you may assign Class-level (static) properties within a class definition by using
@property: value @@ -1330,10 +1318,10 @@ tom.move(); on the right to the variables on the left. In the simplest case, it can be used for parallel assignment:

-
theBait: 1000
-theSwitch: 0
+    
theBait   = 1000
+theSwitch = 0
 
-[theBait, theSwitch]: [theSwitch, theBait]
+[theBait, theSwitch] = [theSwitch, theBait]
 
var _a, theBait, theSwitch;
 theBait = 1000;
 theSwitch = 0;
@@ -1345,17 +1333,16 @@ theBait = 1000;
 theSwitch = 0;
 _a = [theSwitch, theBait];
 theBait = _a[0];
-theSwitch = _a[1];
-;alert(theBait);'>run: theBait
+theSwitch = _a[1];;alert(theBait);'>run: theBait

But it's also helpful for dealing with functions that return multiple values.

-
weatherReport: (location) ->
+    
weatherReport = (location) ->
   # Make an Ajax request to fetch the weather...
   [location, 72, "Mostly Sunny"]
 
-[city, temp, forecast]: weatherReport "Berkeley, CA"
+[city, temp, forecast] = weatherReport "Berkeley, CA"
 
var _a, city, forecast, temp, weatherReport;
 weatherReport = function(location) {
   return [location, 72, "Mostly Sunny"];
@@ -1371,25 +1358,22 @@ weatherReport = function(location) {
 _a = weatherReport("Berkeley, CA");
 city = _a[0];
 temp = _a[1];
-forecast = _a[2];
-;alert(forecast);'>run: forecast
+forecast = _a[2];;alert(forecast);'>run: forecast

Pattern matching can be used with any depth of array and object nesting, to help pull out deeply nested properties.

-
futurists: {
+    
futurists =
   sculptor: "Umberto Boccioni"
   painter:  "Vladimir Burliuk"
-  poet: {
+  poet:
     name:   "F.T. Marinetti"
     address: [
       "Via Roma 42R"
       "Bellagio, Italy 22021"
     ]
-  }
-}
 
-{poet: {name, address: [street, city]}}: futurists
+{poet: {name, address: [street, city]}} = futurists
 
var _a, _b, _c, city, futurists, name, street;
 futurists = {
   sculptor: "Umberto Boccioni",
@@ -1419,14 +1403,13 @@ _b = _a.poet;
 name = _b.name;
 _c = _b.address;
 street = _c[0];
-city = _c[1];
-;alert(name + " — " + street);'>run: name + " — " + street
+city = _c[1];;alert(name + " — " + street);'>run: name + " — " + street

Pattern matching can even be combined with splats.

-
tag: "<impossible>"
+    
tag = "<impossible>"
 
-[open, contents..., close]: tag.split("")
+[open, contents..., close] = tag.split("")
 
 
 
@@ -1444,8 +1427,7 @@ tag = "";
 _a = tag.split("");
 open = _a[0];
 contents = __slice.call(_a, 1, _a.length - 1);
-close = _a[_a.length - 1];
-;alert(contents.join(""));'>run: contents.join("")
+close = _a[_a.length - 1];;alert(contents.join(""));'>run: contents.join("")

@@ -1465,24 +1447,22 @@ close = _a[_a.length - 1]; to use with bind. Functions created with the fat arrow are able to access properties of the this where they're defined.

-
Account: (customer, cart) ->
-  @customer: customer
-  @cart: cart
+    
Account = (customer, cart) ->
+  @customer = customer
+  @cart = cart
 
   $('.shopping_cart').bind 'click', (event) =>
     @customer.purchase @cart
 
var Account;
+var __bind = function(func, context) {
+    return function(){ return func.apply(context, arguments); };
+  };
 Account = function(customer, cart) {
   this.customer = customer;
   this.cart = cart;
-  return $('.shopping_cart').bind('click', (function(__this) {
-    var __func = function(event) {
-      return this.customer.purchase(this.cart);
-    };
-    return (function() {
-      return __func.apply(__this, arguments);
-    });
-  })(this));
+  return $('.shopping_cart').bind('click', __bind(function(event) {
+    return this.customer.purchase(this.cart);
+  }, this));
 };
 

@@ -1498,20 +1478,19 @@ close = _a[_a.length - 1]; snippets of JavaScript within your CoffeeScript, you can use backticks to pass it straight through.

-
hi: `function() {
+    
hi = `function() {
   return [document.title, "Hello JavaScript"].join(": ");
 }`
 
 
 
var hi;
 hi = function() {
-return [document.title, "Hello JavaScript"].join(": ");
+  return [document.title, "Hello JavaScript"].join(": ");
 };
 

+ return [document.title, "Hello JavaScript"].join(": "); +};;alert(hi());'>run: hi()

@@ -1588,9 +1567,9 @@ return [document.title, "Hello JavaScript"].join(": "); from Python — making it easy to test if a value falls within a certain range.

-
cholesterol: 127
+    
cholesterol = 127
 
-healthy: 200 > cholesterol > 60
+healthy = 200 > cholesterol > 60
 
 
 
var cholesterol, healthy;
@@ -1598,8 +1577,7 @@ cholesterol = 127;
 healthy = (200 > cholesterol) && (cholesterol > 60);
 

+healthy = (200 > cholesterol) && (cholesterol > 60);;alert(healthy);'>run: healthy

@@ -1608,41 +1586,39 @@ healthy = (200 > cholesterol) && (cholesterol > 60); is included in CoffeeScript. Simple variables can be included by marking them with a dollar sign.

-
author: "Wittgenstein"
-quote:  "A picture is a fact. -- $author"
+    
author = "Wittgenstein"
+quote  = "A picture is a fact. -- #author"
 
var author, quote;
 author = "Wittgenstein";
 quote = ("A picture is a fact. -- " + author);
 

+quote = ("A picture is a fact. -- " + author);;alert(quote);'>run: quote

And arbitrary expressions can be interpolated by using brackets ${ ... }
Interpolation works the same way within regular expressions.

-
sentence: "${ 22 / 7 } is a decent approximation of π"
+    
sentence = "#{ 22 / 7 } is a decent approximation of π"
 
-sep:   "[.\\/\\- ]"
-dates: /\d+$sep\d+$sep\d+/g
+sep   = "[.\\/\\- ]"
+dates = /\d+$sep\d+$sep\d+/g
 
 
 
var dates, sentence, sep;
 sentence = ("" + (22 / 7) + " is a decent approximation of π");
 sep = "[.\\/\\- ]";
-dates = (new RegExp(("\\d+" + sep + "\\d+" + sep + "\\d+"), "g"));
+dates = /\d+$sep\d+$sep\d+/g;
 

+dates = /\d+$sep\d+$sep\d+/g;;alert(sentence);'>run: sentence

Multiline Strings, Heredocs, and Block Comments Multiline strings are allowed in CoffeeScript.

-
mobyDick: "Call me Ishmael. Some years ago --
+    
mobyDick = "Call me Ishmael. Some years ago --
 never mind how long precisely -- having little
 or no money in my purse, and nothing particular
 to interest me on shore, I thought I would sail
@@ -1663,19 +1639,18 @@ never mind how long precisely -- having little \
 or no money in my purse, and nothing particular \
 to interest me on shore, I thought I would sail \
 about a little and see the watery part of the \
-world...";
-;alert(mobyDick);'>run: mobyDick
+world...";;alert(mobyDick);'>run: mobyDick

Heredocs can be used to hold formatted or indentation-sensitive text (or, if you just don't feel like escaping quotes and apostrophes). The indentation level that begins the heredoc is maintained throughout, so you can keep it all aligned with the body of your code.

-
html: '''
-      <strong>
-        cup of coffeescript
-      </strong>
-      '''
+    
html = '''
+       <strong>
+         cup of coffeescript
+       </strong>
+       '''
 
var html;
 html = '<strong>\n  cup of coffeescript\n</strong>';
 

@@ -1683,9 +1658,9 @@ html = '< Double-quoted heredocs, like double-quoted strings, allow interpolation.

- Sometimes you'd like to pass a block comment through to the generated - JavaScript. For example, when you need to embed a licensing header at - the top of a file. Block comments, which mirror the synax for heredocs, + Sometimes you'd like to pass a block comment through to the generated + JavaScript. For example, when you need to embed a licensing header at + the top of a file. Block comments, which mirror the synax for heredocs, are preserved in the generated code.

###
@@ -1704,8 +1679,8 @@ html = '<
     
 
     

- CoffeeScript includes a simple build system similar to - Make and + CoffeeScript includes a simple build system similar to + Make and Rake. Naturally, it's called Cake, and is used for the build and test tasks for the CoffeeScript language itself. Tasks are defined in a file named Cakefile, and @@ -1721,15 +1696,15 @@ html = '< be made available in the options object. Here's a task that uses the Node.js API to rebuild CoffeeScript's parser:

-
fs: require 'fs'
+    
fs = require 'fs'
 
 option '-o', '--output [DIR]', 'directory for compiled code'
 
 task 'build:parser', 'rebuild the Jison parser', ->
   require 'jison'
-  code:   require('./lib/grammar').parser.generate()
-  dir:    options.output or 'lib'
-  fs.writeFile "$dir/parser.js", code
+  code = require('./lib/grammar').parser.generate()
+  dir  = options.output or 'lib'
+  fs.writeFile "#dir/parser.js", code
 
var fs;
 fs = require('fs');
 option('-o', '--output [DIR]', 'directory for compiled code');