Convert async docs text to markdown, add to sidebar

This commit is contained in:
Geoffrey Booth
2016-12-19 21:50:30 -08:00
parent 69fbb361f2
commit d02376c4c6
2 changed files with 9 additions and 3 deletions

View File

@@ -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 youre 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. Theres no `function*(){}` nonsensea 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(){}` nonsensea 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)
```

View File

@@ -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>