From 56482a31664a14965772f8a48d2bd755e0613e9c Mon Sep 17 00:00:00 2001
From: Geoffrey Booth
"
# Temporary fix until highlight.js adds support for newer CoffeeScript keywords
# Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release
- if file in ['generators', 'modules']
+ if file in ['generator_iteration', 'generators', 'modules']
cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 '
jshtml = "#{hljs.highlight('coffeescript', cs).value}
"
append = if executable is yes then '' else "alert(#{executable});"
diff --git a/documentation/examples/generator_iteration.coffee b/documentation/examples/generator_iteration.coffee
new file mode 100644
index 0000000000..ec98b08f14
--- /dev/null
+++ b/documentation/examples/generator_iteration.coffee
@@ -0,0 +1,13 @@
+fibonacci = ->
+ [previous, current] = [1, 1]
+ loop
+ [previous, current] = [current, previous + current]
+ yield current
+ return
+
+getFibonacciNumbers = (length) ->
+ results = [1]
+ for n from fibonacci()
+ results.push n
+ break if results.length is length
+ results
diff --git a/documentation/index.html.js b/documentation/index.html.js
index 75bf60c954..6edec190c3 100644
--- a/documentation/index.html.js
+++ b/documentation/index.html.js
@@ -107,8 +107,17 @@
compiles one-to-one into the equivalent JS, and there is
no interpretation at runtime. You can use any existing JavaScript library
seamlessly from CoffeeScript (and vice-versa). The compiled output is
- readable and pretty-printed, will work in every JavaScript runtime, and tends
- to run as fast or faster than the equivalent handwritten JavaScript.
+ readable, pretty-printed, and tends to run as fast or faster than the
+ equivalent handwritten JavaScript.
+ #{hljs.highlight('javascript', js).value}
+ The CoffeeScript compiler goes to great lengths to generate output JavaScript + that runs in every JavaScript runtime, but there are exceptions. Use + generator functions only if you know that your + target + runtimes can support them. If you use modules, you + will need to use an additional tool to resolve them.
@@ -577,6 +586,9 @@ Block
check to avoid properties that may be inherited from the prototype, use
for own key, value of object
+ To iterate a generator function, use from
.
+ See Generator Functions.
The only low-level loop that CoffeeScript provides is the while loop. The main difference from JavaScript is that the while loop can be used @@ -864,8 +876,9 @@ Block constructed.
+
CoffeeScript functions also support
- ES6 generator functions
+ ES2015 generator functions
through the yield
keyword. There's no function*(){}
nonsense — a generator in CoffeeScript is simply a function that yields.
yield*
is called yield from
, and yield return
may be used if you need to force a generator that doesn't yield.
+
+
+ You can iterate over a generator function using for…from
.
+
@@ -975,6 +993,7 @@ Block
<%= codeFor('modules') %>
+
Note that the CoffeeScript compiler does not resolve modules; writing an
import
or export
statement in CoffeeScript will produce an
import
or export
statement in the resulting output.
@@ -1393,7 +1412,7 @@ six = ->
<%= releaseHeader('2015-09-03', '1.10.0', '1.9.3') %>
(offsetHeight: height) ->
no longer compiles. That
@@ -1502,7 +1521,7 @@ six = ->
<%= releaseHeader('2015-01-29', '1.9.0', '1.8.0') %>
yield
s.