diff --git a/resources/docs/docs/chapters/tp/arrow-functions.md b/resources/docs/docs/chapters/tp/arrow-functions.md index cd6fc6077954ff01e1ae5112b85f196c5af3f810..c0585d4f6aef18be1e651daf4cd6a35ffd9829c1 100644 --- a/resources/docs/docs/chapters/tp/arrow-functions.md +++ b/resources/docs/docs/chapters/tp/arrow-functions.md @@ -74,16 +74,38 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h > **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> + ??? Show the game.js file - === "game.js - with function" - - ``` js - export class GameComponent { - goToScore() { - // ... - setTimeout( - function () { + === "game.js - with function" + + ``` js + export class GameComponent { + goToScore() { + // ... + setTimeout( + function () { + const scorePage = "#score"; + scorePage + + "?name=" + + this._name + + "&size=" + + this._size + + "&time=" + + timeElapsedInSeconds; + }.bind(this), + 750 + ); + } + } + ``` + + === "game.js - with arrow function" + + ``` js + export class GameComponent { + goToScore() { + // ... + setTimeout(() => { const scorePage = "#score"; scorePage + "?name=" + @@ -92,34 +114,11 @@ Waiting a certain amount of time can be easily done using the [`setTimeout()`](h this._size + "&time=" + timeElapsedInSeconds; - }.bind(this), - 750 - ); - } - } - ``` - - === "game.js - with arrow function" - - ``` js - export class GameComponent { - goToScore() { - // ... - setTimeout(() => { - const scorePage = "#score"; - scorePage + - "?name=" + - this._name + - "&size=" + - this._size + - "&time=" + - timeElapsedInSeconds; - }, 750); + }, 750); + } } - } - ``` + ``` - </details> ## Template literals