This assignment is designed to introduce you to some features in ECMAScript 2015, otherwise known as ES6. From this point on, you are expected to use these features.
By now you should be comfortable writing function expressions and function declarations. Arrow functions are a shorter, more concise way to write a JavaScript function. The syntax might seem strange at first, so try to use arrow functions wherever you can and they will become second nature in no time.
There are a few caveats with arrow functions, though. Most importantly, the this
context is not reset within an arrow function. The value of this
is therefore the same as the this
of the enclosing scope (the surrounding non-arrow function). If there isn’t a non-arrow function scope surrounding, the this
context will be, in the browser, the global window object.
Why does this happen? It happens because arrow functions retain the this
value of the enclosing functional scope. Therefore, you will want to avoid using an arrow function in a constructor (where we need the contextual this
to be the object we are building) or any method that needs to use this
to behave properly.
arrow-functions
. Clone the empty repo to your dev environment.starter-code
into your newly-created repo. Make an initial commit with the unchanged starter code.app.js
file contains examples of function expressions, as you are accustomed to seeing. Work through steps 1-9, reading the notes and reviewing the refactored samples.index.html
file in the browser and verify the correct output in the developer console.