mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Convert async docs text to markdown, add to sidebar
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
## Bound Functions, Generator Functions
|
||||
## Function Modifiers
|
||||
|
||||
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` will be lost. If you’re not familiar with this behavior, [this Digital Web article](http://64.13.255.16/articles/scope_in_javascript/) gives a good overview of the quirks.
|
||||
|
||||
@@ -12,7 +12,7 @@ If we had used `->` in the callback above, `@customer` would have referred to th
|
||||
|
||||
When used in a class definition, methods declared with the fat arrow will be automatically bound to each instance of the class when the instance is constructed.
|
||||
|
||||
CoffeeScript functions also support [ES2015 generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) through the `yield` keyword. There’s no `function*(){}` nonsense — a generator in CoffeeScript is simply a function that yields.
|
||||
CoffeeScript also supports [generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*) and [async functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) through the `yield` and `await` keywords respectively. There's no `function*(){}` or `async function(){}` nonsense—a generator in CoffeeScript is simply a function that yields, and an async function in CoffeeScript is simply a function that awaits.
|
||||
|
||||
```
|
||||
codeFor('generators', 'ps.next().value')
|
||||
@@ -25,3 +25,9 @@ You can iterate over a generator function using `for…from`.
|
||||
```
|
||||
codeFor('generator_iteration', 'getFibonacciNumbers(10)')
|
||||
```
|
||||
|
||||
Similar to how `yield return` forces a generator, `await return` may be used to force a function to be async.
|
||||
|
||||
```
|
||||
codeFor('async', true)
|
||||
```
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<a href="#destructuring" class="nav-link" data-action="sidebar-nav">Destructuring Assignment</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="#fat-arrow" class="nav-link" data-action="sidebar-nav">Bound and Generator Functions</a>
|
||||
<a href="#fat-arrow" class="nav-link" data-action="sidebar-nav">Function Modifiers</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="#embedded" class="nav-link" data-action="sidebar-nav">Embedded JavaScript</a>
|
||||
|
||||
Reference in New Issue
Block a user