From f7692c92ce61c277a3f9a38c6bdbe712730d040a Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas
- CoffeeScript function support - ES6 generator functions - through the yield keyword. There's no function*(){} - nonsense — a generator in CoffeeScript is simply a function that yields. -
- <%= codeFor('generators', 'ps.next().value') %>@@ -800,7 +793,7 @@ Expressions
- Function binding + Bound Functions, Generator Functions In JavaScript, the this keyword is dynamically scoped to mean the object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this @@ -827,6 +820,13 @@ Expressions be automatically bound to each instance of the class when the instance is constructed.
++ CoffeeScript functions also support + ES6 generator functions + through the yield keyword. There's no function*(){} + nonsense — a generator in CoffeeScript is simply a function that yields. +
+ <%= codeFor('generators', 'ps.next().value') %>
diff --git a/index.html b/index.html
index 3678923e..9fb46c01 100644
--- a/index.html
+++ b/index.html
@@ -34,7 +34,7 @@
Operators and Aliases
Classes, Inheritance, and Super
Destructuring Assignment
- Function Binding
+ Bound and Generator Functions
Embedded JavaScript
Switch and Try/Catch
Chained Comparisons
@@ -576,44 +576,6 @@ fill = function(container, liquid) {
return "Filling the " + container + " with " + liquid + "...";
};
;alert(fill("cup"));'>run: fill("cup")
-
- CoffeeScript function support - ES6 generator functions - through the yield keyword. There's no function*(){} - nonsense — a generator in CoffeeScript is simply a function that yields. -
-perfectSquares = ->
- num = 0
- loop
- num += 1
- yield num * num
- return
-
-window.ps or= perfectSquares()
var perfectSquares;
-
-perfectSquares = function*() {
- var num;
- num = 0;
- while (true) {
- num += 1;
- (yield num * num);
- }
-};
-
-window.ps || (window.ps = perfectSquares());
-
@@ -663,7 +625,7 @@ kids = { age: 9 } }; -
+
@@ -725,7 +687,7 @@ changeNumbers = function
@@ -866,7 +828,7 @@ alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);
-
Comprehensions should be able to handle most places where you otherwise
would use a loop, each/forEach, map, or select/filter, for example:
@@ -953,7 +915,7 @@ countdown = (functionreturn _results;
})();
-
@@ -1145,7 +1107,7 @@ middle = numbers.slice(3, -22);
copy = numbers.slice(0);
-
The Existential Operator
@@ -1454,7 +1416,7 @@ speed = 0;
}
footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";
-
Soaking up nulls is similar to Ruby's
andand gem, and to the
@@ -1594,7 +1556,7 @@ tom = new Horse("Tommy the Pal
sam.move();
tom.move();
-
If we had used -> in the callback above, @customer would
have referred to the undefined "customer" property of the DOM element,
@@ -1913,6 +1875,44 @@ Account = function
+
+ CoffeeScript functions also support
+ ES6 generator functions
+ through the yield keyword. There's no function*(){}
+ nonsense — a generator in CoffeeScript is simply a function that yields.
+
+
+
@@ -1271,7 +1233,7 @@ globals = ((functionreturn _results;
})()).slice(0, 10);
-
+
+
@@ -1703,7 +1665,7 @@ theBait = 1000;
theSwitch = 0;
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
-
+
perfectSquares = ->
+ num = 0
+ loop
+ num += 1
+ yield num * num
+ return
+
+window.ps or= perfectSquares()
var perfectSquares;
+
+perfectSquares = function*() {
+ var num;
+ num = 0;
+ while (true) {
+ num += 1;
+ (yield num * num);
+ }
+};
+
+window.ps || (window.ps = perfectSquares());
+