js generator
function* fibonacci() {
var a = yield 1;
yield a * 2;
}
var it = fibonacci();
console.log(it); // "Generator { }"
console.log(it.next()); // 1
console.log(it.send(10)); // 20
console.log(it.close()); // undefined
console.log(it.next()); // throws StopIteration (as the generator is now closed)
function* name([param[, param[, ... param]]]) {
statements
}
function* forever() {
let index = 0;
while (true) {
yield index++;
}
}
let f = forever();
console.log(f.next()); // 0
console.log(f.next()); // 1
console.log(f.next()); // 2
Also in JavaScript:
- Expected an assignment or function call and instead saw an expression
- how to delete a cookie in js
- what is a promise
- create react app theme_color
- javascript settimeout loop
- js validate email
- vuex namespaced getters
- merge array in js
- get date and change format and increase date or month in javascript jquery
- javascript short syntax get element
- mongoose reference another model
- add countdown timer to javascript quiz
- blank catch js
- what is angularjs used for
- jquery function
- regex check from a-z 0-9
- javascript throw new error
- jquery copy to clipboard
- mysql json array contains
- chart.js on hover and onclick event
- How to get the path to the file that required your module?
- fizzbuzz javascript
- make indexOF in js
- changing map style react-leaflet