Please enable JavaScript.
Coggle requires JavaScript to display documents.
Javascript ES6 (Generators (What is a generator? (A generator is a…
Javascript ES6
Generators
What is a generator?
A generator is a function that can be entered and exited multiple times
See
this example
A generator has a syntax similar to a function with one difference
Syntax:
function* numbers() { ... }
The function declaration has a asterix after it
What does a generator do?
What do we use them for?
Generator functions work perfect with
for of
loops
Practical use of a
ES6 generator function
Promises
Codepen Example
Three states of promises
#
'unresolved'
Waiting for something to finish
Promise begins in an unresolved state
'resolved'
Something finished and it went ok
'rejected'
Something finished but went badly
The flow of a promise
Promise
Status: 'resolved'
Callback Keyword:
then
Status: 'rejected'
Callback Keyword:
catch
Fetch
ES6 AJAX requests
Also uses promises
#
Codepen
Desctructoring
Break down an object and declare
it into a new variable
Example:
let obj = { name: 'Michael' },
Descructoring looks like this:
let { name } = obj;
The variable 'name' now equals 'Michael'
Array descructoring
Classes
New way of declaring object literals
New way of doing prototypal inheritance
Example:
class Monster {
constructor (options) {
this.name = options.name
}
}
Extending to another object looks like:
class Snake
extends
Monster {
constructor(options) {
super(options)
}
}
Extends
is used for prototypal inheritance