Permalink
Browse files

CoffeeScript 0.2.5 is on the books

  • Loading branch information...
1 parent ed8a549 commit e77e5206079efc1b74a32a0fcedfe663436a5b2a @jashkenas jashkenas committed Jan 14, 2010
View
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'coffee-script'
- s.version = '0.2.4' # Keep version in sync with coffee-script.rb
- s.date = '2010-1-12'
+ s.version = '0.2.5' # Keep version in sync with coffee-script.rb
+ s.date = '2010-1-13'
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
@@ -0,0 +1,6 @@
+Account: customer, cart =>
+ this.customer: customer
+ this.cart: cart
+
+ $('.shopping_cart').bind('click') event ==>
+ this.customer.purchase(this.cart)
@@ -1,9 +1,10 @@
switch day
- when "Tuesday" then eat_breakfast()
- when "Wednesday" then go_to_the_park()
- when "Saturday"
+ when "Mon" then go_to_work()
+ when "Tue" then go_to_the_park()
+ when "Thu" then go_ice_fishing()
+ when "Fri", "Sat"
if day is bingo_day
go_to_bingo()
go_dancing()
- when "Sunday" then go_to_church()
+ when "Sun" then go_to_church()
else go_to_work()
@@ -1,5 +1,8 @@
-while demand > supply
- sell()
- restock()
+if this.studying_economics
+ while supply > demand then buy()
+ while supply < demand then sell()
-while supply > demand then buy()
+num: 6
+lyrics: while num -= 1
+ num + " little monkeys, jumping on the bed.
+ One fell out and bumped his head."
@@ -51,7 +51,7 @@
<p>
<b>Latest Version:</b>
- <a href="http://gemcutter.org/gems/coffee-script">0.2.4</a>
+ <a href="http://gemcutter.org/gems/coffee-script">0.2.5</a>
</p>
<h2>Table of Contents</h2>
@@ -76,6 +76,7 @@
<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="#long_arrow">Function Binding</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 />
@@ -387,9 +388,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<p id="while">
<b class="header">While Loops</b>
- The only low-level loop that CoffeeScript provides is the while loop.
+ The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
+ main difference from JavaScript is that the <b>while</b> loop can be used
+ as an expression, returning an array containing the result of each iteration
+ through the loop.
</p>
- <%= code_for('while') %>
+ <%= code_for('while', 'lyrics.join("\n")') %>
<p>
Other JavaScript loops, such as <b>for</b> loops and <b>do-while</b> loops
can be mimicked by variations on <b>while</b>, but the hope is that you
@@ -528,6 +532,17 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
</p>
<%= code_for('object_extraction', 'poet + " — " + street') %>
+ <p id="long_arrow">
+ <b class="header">Function binding</b>
+ The long arrow <tt>==></tt> can be used to both define a function, and to bind
+ it to the current value of <tt>this</tt>, right on the spot. This is helpful
+ when using callback-based libraries like Prototype or jQuery, for creating
+ iterator functions to pass to <tt>each</tt>, or event-handler functions
+ to use with <tt>bind</tt>. Functions created with the long arrow are able to access
+ properties of the <tt>this</tt> where they're defined.
+ </p>
+ <%= code_for('long_arrow') %>
+
<p id="embedded">
<b class="header">Embedded JavaScript</b>
Hopefully, you'll never need to use it, but if you ever need to intersperse
@@ -546,6 +561,11 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
in a returnable, assignable expression. The format is: <tt>switch</tt> condition,
<tt>when</tt> clauses, <tt>else</tt> the default case.
</p>
+ <p>
+ As in Ruby, <b>switch</b> statements in CoffeeScript can take multiple
+ values for each <b>when</b> clause. If any of the values match, the clause
+ runs.
+ </p>
<%= code_for('switch') %>
<p id="try">
@@ -624,7 +644,16 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
</ul>
<h2 id="change_log">Change Log</h2>
-
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.5</b>
+ The conditions in switch statements can now take multiple values at once &mdash;
+ If any of them are true, the case will run. Added the long arrow <tt>==></tt>,
+ which defines and immediately binds a function to <tt>this</tt>. While loops can
+ now be used as expressions, in the same way that comprehensions can. Splats
+ can be used within pattern matches to soak up the rest of an array.
+ </p>
+
<p>
<b class="header" style="margin-top: 20px;">0.2.4</b>
Added ECMAScript Harmony style destructuring assignment, for dealing with
@@ -3,18 +3,18 @@
// Eat lunch.
lunch = (function() {
__a = []; __b = ['toast', 'cheese', 'wine'];
- for (__c=0; __c<__b.length; __c++) {
+ for (__c = 0; __c < __b.length; __c++) {
food = __b[__c];
__a.push(eat(food));
}
return __a;
})();
// Naive collision detection.
__d = asteroids;
- for (__e=0; __e<__d.length; __e++) {
+ for (__e = 0; __e < __d.length; __e++) {
roid = __d[__e];
__f = asteroids;
- for (__g=0; __g<__f.length; __g++) {
+ for (__g = 0; __g < __f.length; __g++) {
roid2 = __f[__g];
if (roid !== roid2) {
if (roid.overlaps(roid2)) {
@@ -1,10 +1,11 @@
(function(){
var __a, __b, globals, name;
+ var __hasProp = Object.prototype.hasOwnProperty;
// The first ten global properties.
globals = ((function() {
__a = []; __b = window;
for (name in __b) {
- if (__b.hasOwnProperty(name)) {
+ if (__hasProp.call(__b, name)) {
__a.push(name);
}
}
@@ -0,0 +1,20 @@
+(function(){
+ var Account;
+ Account = function Account(customer, cart) {
+ var __a, __b;
+ var __this = this;
+ this.customer = customer;
+ this.cart = cart;
+ __a = $('.shopping_cart').bind('click', (function() {
+ __b = function(event) {
+ var __c;
+ __c = this.customer.purchase(this.cart);
+ return Account === this.constructor ? this : __c;
+ };
+ return (function() {
+ return __b.apply(__this, arguments);
+ });
+ })());
+ return Account === this.constructor ? this : __a;
+ };
+})();
@@ -1,5 +1,6 @@
(function(){
var __a, __b, age, ages, child, years_old;
+ var __hasProp = Object.prototype.hasOwnProperty;
years_old = {
max: 10,
ida: 9,
@@ -9,7 +10,7 @@
__a = []; __b = years_old;
for (child in __b) {
age = __b[child];
- if (__b.hasOwnProperty(child)) {
+ if (__hasProp.call(__b, child)) {
__a.push(child + " is " + age);
}
}
@@ -34,7 +34,7 @@
// Array comprehensions:
cubed_list = (function() {
__a = []; __b = list;
- for (__c=0; __c<__b.length; __c++) {
+ for (__c = 0; __c < __b.length; __c++) {
num = __b[__c];
__a.push(math.cube(num));
}
View
@@ -1,14 +1,16 @@
(function(){
- if (day === "Tuesday") {
- eat_breakfast();
- } else if (day === "Wednesday") {
+ if (day === "Mon") {
+ go_to_work();
+ } else if (day === "Tue") {
go_to_the_park();
- } else if (day === "Saturday") {
+ } else if (day === "Thu") {
+ go_ice_fishing();
+ } else if (day === "Fri" || day === "Sat") {
if (day === bingo_day) {
go_to_bingo();
go_dancing();
}
- } else if (day === "Sunday") {
+ } else if (day === "Sun") {
go_to_church();
} else {
go_to_work();
View
@@ -1,9 +1,20 @@
(function(){
- while (demand > supply) {
- sell();
- restock();
- }
- while (supply > demand) {
- buy();
+ var __a, lyrics, num;
+ if (this.studying_economics) {
+ while (supply > demand) {
+ buy();
+ }
+ 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;
+ })();
})();
Oops, something went wrong.

0 comments on commit e77e520

Please sign in to comment.