I am a bit confused about when a value is yielded in JS 1.7's new yield feature.
When I write my function like this:
function helloWorld() {
console.log('hello');
yield "world";
}
var sayHello = helloWorld();
sayHello.next();
It returns:
>"world"
>"hello"
But when I write my function like this:
function helloWorld() {
console.log('hello');
yield console.log("world");
}
var sayHello = helloWorld();
sayHello.next();
It returns:
>"hello"
>"world"
as I would expect.
I am confused as to why in the first case "world" returns before "hello", perhaps I do not understand how yield works, could anyone who might know elaborate on why yield behaves this way?