2116790
这两天在研究koa框架(可以参见http://koa.rednode.cn/ ), 但是里面的函数名好多都是*,运行的时候根本跑步起来。。
文档有有这样一段: 与普通的 function 不同,generator functions 以 function* 声明。以这种关键词声明的函数支持 yield
是我的方法不对嘛?
下面是文档中的代码。。。
var koa = require('koa'); var app = koa();
// x-response-time
app.use(function *(next){ var start = new Date; yield next; var ms = new Date - start; this.set('X-Response-Time', ms + 'ms'); });
// logger
app.use(function *(next){ var start = new Date; yield next; var ms = new Date - start; console.log('%s %s - %s', this.method, this.url, ms); });
// response
app.use(function *(){ this.body = 'Hello World'; });
app.listen(3000);