Skip to content
Snippets Groups Projects
Commit 9dcf00a0 authored by Olivier ABDELNOUR's avatar Olivier ABDELNOUR
Browse files

wup

parent ad38a96e
No related branches found
No related tags found
No related merge requests found
Pipeline #59985 passed
......@@ -50,7 +50,7 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h
Follow `TODO #arrow-function` comments for instructions.
> Example:
>
> anonymous function
> === "Anonymous function"
>
> ``` js
> setTimeout(function () {
......@@ -58,7 +58,7 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h
> }, 1000);
> ```
>
> arrow function
> === "Arrow function"
>
> ``` js
> setTimeout(() => {
......@@ -66,18 +66,16 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h
> }, 1000);
> ```
>
> arrow function - single line
> === "Arrow function - single line"
>
> ```js{}
> ``` js
> setTimeout(() => console.log("after 1s"), 1000);
>
>
> ```
> **danger** Regular functions declared with the **`function` keyword have `this` inherited from the caller**, whereas **arrow functions have a `this` inherited from the declaring scope**.
<details><summary> Show the game.js file </summary>
game.js - with function
=== "game.js - with function"
```javascript
export class GameComponent {
......@@ -100,7 +98,7 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h
}
```
game.js - with arrow function
=== "game.js - with arrow function"
```javascript
export class GameComponent {
......@@ -125,7 +123,7 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h
Concatenating strings is not something we enjoy in any language. Fortunately, _ES6_ comes with [**template literals**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) as an alternative:
=== "without template literals"
=== "Without template literals"
``` js
const welcome =
......@@ -133,34 +131,13 @@ Concatenating strings is not something we enjoy in any language. Fortunately, _E
+ "You have " + messages.length + " message" + messages.length ? "s" : "" + "to read.";
```
=== "with template literals"
=== "With template literals"
``` js
const welcome =
`welcome back ${user.name}.
You have ${messages.length} message${messages.length ? "s" : ""} to read.`;
```
=== "C"
``` c
#include <stdio.h>
int main(void) {
printf("Hello world!\n");
return 0;
}
```
=== "C++"
``` c++
#include <iostream>
int main(void) {
std::cout << "Hello world!" << std::endl;
return 0;
}
```
### Use backquotes instead of quotes <Diy />
......@@ -181,9 +158,3 @@ src/app/scripts/welcome.js
- [ ] I know what is the _bound this_ of a function
- [ ] I know about template literals
- [ ] The application runs as usual
<GitCommit />
## <i class="fas fa-graduation-cap"></i> Assessment
<iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfeoczEA0VJINo3ty3W-gUzvkA8E26VKXM4U_TOKnZ5mXplkw/viewform?embedded=true" width="100%" height="640" frameborder="0" marginheight="0" marginwidth="0">Chargement…</iframe>
......@@ -14,13 +14,9 @@ nav:
- "Functionnal programming": chapters/tp/functionnal-programming.md
- "Asynchronous": chapters/tp/asynchronous.md
- "sourcemaps": chapters/tp/sourcemaps.md
- "Component Oriented Architecture": chapters/tp/components.md
- "Ensure old browser compatibility": chapters/tp/babel.md
- "arrow functions": chapters/tp/arrow-functions.md
- "arrow functions": chapters/tp/style.md
- "functionnal programming": chapters/tp/functionnal-programming.md
- "ending": chapters/tp/ending.md
- "Ending": chapters/tp/ending.md
- Practice:
- "practise": chapters/practice/practise.md
- "bonuses": chapters/practice/bonuses.md
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment