Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upnew for generator does do something useful #301
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
claudepache
Jan 20, 2016
Contributor
Just use a wrapper.
function start_counter() {
function* crank() {
const next = x => count.next( x ),
turn = x => setTimeout( () => next( x ), 100 );
let x = 1;
while( true ) console.log( x = x < 12 ? yield turn( x + 1 ) : yield turn( 1 ) );
}
const count = crank();
count.next();
}
start_counter(); // implementation details hidden: no "new", no "next"Anyway, that sort of discussion should go to the es-discuss mailing list.
|
Just use a wrapper. function start_counter() {
function* crank() {
const next = x => count.next( x ),
turn = x => setTimeout( () => next( x ), 100 );
let x = 1;
while( true ) console.log( x = x < 12 ? yield turn( x + 1 ) : yield turn( 1 ) );
}
const count = crank();
count.next();
}
start_counter(); // implementation details hidden: no "new", no "next"Anyway, that sort of discussion should go to the es-discuss mailing list. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
domenic
closed this
Jan 20, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ghost commentedJan 20, 2016
RE: https://github.com/tc39/tc39-notes/blob/master/es7/2015-07/july-28.md#67-new--generatorfunction
Actually you can do this :
Having a reference to itself, allows the generator to yield control flow to other operation, before returning to itself and continue processing.
This is useful.
Without [[construct]] trap for generators this is required: