Skip to content

Commit

Permalink
Adds warning for 11ty/eleventy#934
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 14, 2020
1 parent dd581b5 commit 24a1ac0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/languages/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,30 @@ This is the same as the example above but adds `await` before the function is ca
{% codetitle "js-async-fn-example.11ty.js" %}

{% raw %}
```
```js
module.exports = function(data) {
return `<h1>${await this.myAsyncFunction(data.a, data.b)}</h1>`;
};
```
{% endraw %}

### Warning about Arrow Functions

{% callout "warn" %}
Note that by definition (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#No_separate_this">read on MDN</a>) arrow functions do not have access to <code>this</code>, so any use of JavaScript Functions inside of an arrow function template will throw an error.
{% endcallout %}

{% codetitle "js-arrow-fn-example.11ty.js" %}

{% raw %}
```js
module.exports = (data) => {
// Using `this` in an arrow function will throw an error!
return `<h1>${await this.myFunction(data.a, data.b)}</h1>`;
};
```
{% endraw %}

### Relationship to Filters and Shortcodes

Any universal filters or shortcodes will also be available as as JavaScript Template Functions.
Expand Down

0 comments on commit 24a1ac0

Please sign in to comment.