Generator functions in JavaScript

function* gen() {
    var x = 0
    while (true) yield x++
}