Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 11 commits
  • 24 files changed
  • 0 commit comments
  • 1 contributor
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'coffee-script'
- s.version = '0.2.3' # Keep version in sync with coffee-script.rb
- s.date = '2010-1-10'
+ s.version = '0.2.4' # Keep version in sync with coffee-script.rb
+ s.date = '2010-1-12'
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
@@ -0,0 +1,5 @@
+html: '''
+ <strong>
+ cup of coffeescript
+ </strong>
+ '''
@@ -0,0 +1,5 @@
+weather_report: location =>
+ # Make an Ajax request to fetch the weather...
+ [location, 72, "Mostly Sunny"]
+
+[city, temp, forecast]: weather_report("Berkeley, CA")
@@ -0,0 +1,13 @@
+futurists: {
+ sculptor: "Umberto Boccioni"
+ painter: "Vladimir Burliuk"
+ poet: {
+ name: "F.T. Marinetti"
+ address: [
+ "Via Roma 42R"
+ "Bellagio, Italy 22021"
+ ]
+ }
+}
+
+{poet: {name: poet, address: [street, city]}}: futurists
@@ -0,0 +1,4 @@
+bait: 1000
+and_switch: 0
+
+[bait, and_switch]: [and_switch, bait]
@@ -51,7 +51,7 @@
<p>
<b>Latest Version:</b>
- <a href="http://gemcutter.org/gems/coffee-script">0.2.3</a>
+ <a href="http://gemcutter.org/gems/coffee-script">0.2.4</a>
</p>
<h2>Table of Contents</h2>
@@ -75,10 +75,11 @@
<a href="#expressions">Everything is an Expression</a><br />
<a href="#inheritance">Inheritance, and Calling Super from a Subclass</a><br />
<a href="#blocks">Blocks</a><br />
+ <a href="#pattern_matching">Pattern Matching</a><br />
<a href="#embedded">Embedded JavaScript</a><br />
<a href="#switch">Switch/When/Else</a><br />
<a href="#try">Try/Catch/Finally</a><br />
- <a href="#strings">Multiline Strings</a><br />
+ <a href="#strings">Multiline Strings and Heredocs</a><br />
<a href="#resources">Resources</a><br />
<a href="#contributing">Contributing</a><br />
<a href="#change_log">Change Log</a><br />
@@ -95,7 +96,7 @@
<a href="documentation/underscore.html">Underscore.coffee</a>, a port
of the <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
library of helper functions. Underscore.coffee can pass the entire Underscore.js
- test suite. The CoffeeScript version is faster than the original for a number
+ test suite. The CoffeeScript version is faster than the original for a number
of methods (in general, due to the speed of CoffeeScript's array comprehensions), and
after being minified and gzipped, is only 241 bytes larger than the original
JavaScript version.
@@ -415,7 +416,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<%= code_for('range_comprehensions', 'countdown') %>
<p>
Comprehensions can also be used to iterate over the keys and values in
- an object. Use <tt>of</tt> to signal comprehension over the properties of
+ an object. Use <tt>of</tt> to signal comprehension over the properties of
an object instead of the values in an array.
</p>
<%= code_for('object_comprehensions', 'ages.join(", ")') %>
@@ -481,12 +482,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
be completely usable if it weren't for a couple of small exceptions:
it's awkward to call <b>super</b> (the prototype object's
implementation of the current function), and it's awkward to correctly
- set the prototype chain.
+ set the prototype chain.
</p>
<p>
CoffeeScript provides <tt>extends</tt>
to help with prototype setup, <tt>::</tt> for quick access to an
- object's prototype, and converts <tt>super()</tt> into a call against
+ object's prototype, and converts <tt>super()</tt> into a call against
the immediate ancestor's method of the same name.
</p>
<%= code_for('super', true) %>
@@ -499,11 +500,39 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
so you don't have to close the parentheses on the other side.
</p>
<%= code_for('blocks') %>
+ <p>
+ If you prefer not to use blocks, you'll need to add a pair of parentheses
+ to help distinguish the arguments from the definition of the function:
+ <tt>_.map(array, (num => num * 2))</tt>
+ </p>
+
+ <p id="pattern_matching">
+ <b class="header">Pattern Matching (Destructuring Assignment)</b>
+ To make extracting values from complex arrays and objects more convenient,
+ CoffeeScript implements ECMAScript Harmony's proposed
+ <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">destructuring assignment</a>
+ syntax. When you assign an array or object literal to a value, CoffeeScript
+ breaks up and matches both sides against each other, assigning the values
+ on the right to the variables on the left. In the simplest case, it can be
+ used for parallel assignment:
+ </p>
+ <%= code_for('parallel_assignment', 'bait') %>
+ <p>
+ But it's also helpful for dealing with functions that return multiple
+ values.
+ </p>
+ <%= code_for('multiple_return_values', 'forecast') %>
+ <p>
+ Pattern matching can be used with any depth of array and object nesting,
+ to help pull out deeply nested properties.
+ </p>
+ <%= code_for('object_extraction', 'poet + " — " + street') %>
<p id="embedded">
<b class="header">Embedded JavaScript</b>
- If you ever need to interpolate literal JavaScript snippets, you can
- use backticks to pass JavaScript straight through.
+ Hopefully, you'll never need to use it, but if you ever need to intersperse
+ snippets of JavaScript within your CoffeeScript, you can
+ use backticks to pass it straight through.
</p>
<%= code_for('embedded', 'hi()') %>
@@ -527,10 +556,17 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<%= code_for('try') %>
<p id="strings">
- <b class="header">Multiline Strings</b>
+ <b class="header">Multiline Strings and Heredocs</b>
Multiline strings are allowed in CoffeeScript.
</p>
<%= code_for('strings', 'moby_dick') %>
+ <p>
+ 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.
+ </p>
+ <%= code_for('heredocs') %>
<h2 id="resources">Resources</h2>
@@ -539,7 +575,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<a href="http://github.com/jashkenas/coffee-script/">Source Code</a><br />
After checking out the source, make sure to run <tt>rake build:parser</tt>
to generate an up-to-date version of the Racc parser.
- Use <tt>bin/coffee</tt> to test your changes,
+ Use <tt>bin/coffee</tt> to test your changes,
<tt>rake test</tt> to run the test suite,
and <tt>rake gem:install</tt> to
create and install a custom version of the gem.
@@ -590,9 +626,16 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<h2 id="change_log">Change Log</h2>
<p>
+ <b class="header" style="margin-top: 20px;">0.2.4</b>
+ Added ECMAScript Harmony style destructuring assignment, for dealing with
+ extracting values from nested arrays and objects. Added indentation-sensitive
+ heredocs for nicely formatted strings or chunks of code.
+ </p>
+
+ <p>
<b class="header" style="margin-top: 20px;">0.2.3</b>
Axed the unsatisfactory <tt>ino</tt> keyword, replacing it with <tt>of</tt> for
- object comprehensions. They now look like: <tt>for key, value of object</tt>.
+ object comprehensions. They now look like: <tt>for prop, value of object</tt>.
</p>
<p>
@@ -2,12 +2,12 @@
var __a, __b, __c, __d, __e, __f, __g, food, lunch, roid, roid2;
// Eat lunch.
lunch = (function() {
- __c = []; __a = ['toast', 'cheese', 'wine'];
- for (__b=0; __b<__a.length; __b++) {
- food = __a[__b];
- __c.push(eat(food));
+ __a = []; __b = ['toast', 'cheese', 'wine'];
+ for (__c=0; __c<__b.length; __c++) {
+ food = __b[__c];
+ __a.push(eat(food));
}
- return __c;
+ return __a;
})();
// Naive collision detection.
__d = asteroids;
@@ -2,12 +2,12 @@
var __a, __b, globals, name;
// The first ten global properties.
globals = ((function() {
- __b = []; __a = window;
- for (name in __a) {
- if (__a.hasOwnProperty(name)) {
- __b.push(name);
+ __a = []; __b = window;
+ for (name in __b) {
+ if (__b.hasOwnProperty(name)) {
+ __a.push(name);
}
}
- return __b;
+ return __a;
})()).slice(0, 10);
})();
@@ -0,0 +1,4 @@
+(function(){
+ var html;
+ html = "<strong>\n cup of coffeescript\n</strong>";
+})();
@@ -0,0 +1,11 @@
+(function(){
+ var __a, city, forecast, temp, weather_report;
+ weather_report = function weather_report(location) {
+ // Make an Ajax request to fetch the weather...
+ return [location, 72, "Mostly Sunny"];
+ };
+ __a = weather_report("Berkeley, CA");
+ city = __a[0];
+ temp = __a[1];
+ forecast = __a[2];
+})();
@@ -6,13 +6,13 @@
tim: 11
};
ages = (function() {
- __b = []; __a = years_old;
- for (child in __a) {
- age = __a[child];
- if (__a.hasOwnProperty(child)) {
- __b.push(child + " is " + age);
+ __a = []; __b = years_old;
+ for (child in __b) {
+ age = __b[child];
+ if (__b.hasOwnProperty(child)) {
+ __a.push(child + " is " + age);
}
}
- return __b;
+ return __a;
})();
})();
@@ -0,0 +1,17 @@
+(function(){
+ var __a, __b, __c, city, futurists, poet, 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;
+ poet = __b.name;
+ __c = __b.address;
+ street = __c[0];
+ city = __c[1];
+})();
@@ -33,11 +33,11 @@
}
// Array comprehensions:
cubed_list = (function() {
- __c = []; __a = list;
- for (__b=0; __b<__a.length; __b++) {
- num = __a[__b];
- __c.push(math.cube(num));
+ __a = []; __b = list;
+ for (__c=0; __c<__b.length; __c++) {
+ num = __b[__c];
+ __a.push(math.cube(num));
}
- return __c;
+ return __a;
})();
})();
@@ -0,0 +1,8 @@
+(function(){
+ var __a, and_switch, bait;
+ bait = 1000;
+ and_switch = 0;
+ __a = [and_switch, bait];
+ bait = __a[0];
+ and_switch = __a[1];
+})();
@@ -1,21 +1,21 @@
(function(){
var __a, __b, __c, __d, __e, countdown, egg_delivery, num;
countdown = (function() {
- __b = []; __d = 10; __e = 1;
+ __a = []; __d = 10; __e = 1;
for (__c=0, num=__d; (__d <= __e ? num <= __e : num >= __e); (__d <= __e ? num += 1 : num -= 1), __c++) {
- __b.push(num);
+ __a.push(num);
}
- return __b;
+ return __a;
})();
egg_delivery = function egg_delivery() {
var __f, __g, __h, __i, __j, dozen_eggs, i;
- __g = []; __i = 0; __j = eggs.length;
+ __f = []; __i = 0; __j = eggs.length;
for (__h=0, i=__i; (__i <= __j ? i < __j : i > __j); (__i <= __j ? i += 12 : i -= 12), __h++) {
- __g.push((function() {
+ __f.push((function() {
dozen_eggs = eggs.slice(i, i + 12);
return deliver(new egg_carton(dozen));
})());
}
- return __g;
+ return __f;
};
})();
Oops, something went wrong.

No commit comments for this range