Koa 用的都是中间键,而这些中间键的顺序是压栈.例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| let koa = require('koa'); let app = new koa();
app.use((ctx, next) => { console.log(1) next(); console.log(5) });
app.use((ctx, next) => { console.log(2) next(); console.log(4) });
app.use((ctx, next) => { console.log(3) ctx.body = 'Hello World'; });
app.listen(3000);
|
这里console.log(3)以后会去取最新入栈的 console.log(4), 而不是5