ES6——yield例子

1.

// function* demo() {
//  foo(yield 'a', yield 'b'); // OK
// let input = yield; // OK
// }
function* demo() {
//  console.log('Hello' + yield); // SyntaxError
//  console.log('Hello' + yield 123); // SyntaxError
 console.log('Hello1' + (yield)); // OK
 console.log('Hello2' + (yield 123)); // OK
}
var d = demo()
var res = d.next()
while(!res.done){
    console.log("test" + res.value);
    res = d.next();
}

原文地址:https://www.cnblogs.com/sunupo/p/15492292.html