For me, it is the only new feature that really improves the way I write code every day. Yes, arrow functions are nice, yes, classes are nice, but we could do all the same things before, right? Generator functions allow us to do things, that were not possible before!
Generators alone don't give much benefit, but if you use them with co and koa - Oh. My. God.
I've never had so much pleasure writing JavaScript before. It's just beautiful:
let post = yield Post.findOne();
post.title = 'New title';
yield post.save();
I know it's unofficial way of using generators, but with ES7 async/await, all we have to do is to switch function * myFn () to async myFn () and yield myFn() to await myFn() and we are golden.
Generator functions and only generator functions.
For me, it is the only new feature that really improves the way I write code every day. Yes, arrow functions are nice, yes, classes are nice, but we could do all the same things before, right? Generator functions allow us to do things, that were not possible before!
Generators alone don't give much benefit, but if you use them with co and koa - Oh. My. God.
I've never had so much pleasure writing JavaScript before. It's just beautiful:
I know it's unofficial way of using generators, but with ES7
async/await
, all we have to do is to switchfunction * myFn ()
toasync myFn ()
andyield myFn()
toawait myFn()
and we are golden.