I saw something strange in Koa . It has several new function names (from https://github.com/koajs/koa/blob/master/examples/co.js#L10 ):
app.use(function(){ return function *(){ var paths = yield fs.readdir('docs'); var files = yield paths.map(function(path){ return fs.readFile('docs/' + path, 'utf8'); }); this.type = 'markdown'; this.body = files.join(''); } });
What does return function *() mean? Can we declare a function named * in JavaScript?
return function *()
*
This means that the function returns an iterator (so it can be called multiple times with .next () to get more values.
browse http://wingolog.org/archives/2013/05/08/generators-in-v8 for more information
This is an ES6 construct, so at the moment you see it more in node and not on client side js
Koa uses a new JavaScript feature called generators, and * is a way to identify the generator in V8.