我有一个koa应用程序,它有一堆功能被分成单独的文件。当调用一个路由时,我需要将上下文传递this给单独文件中的另一个函数(这也是一个路由)。
文件a.js路径 -http://127.0.0.1:3000/foo
exports.foo = function *() {
this.body = 'Some Value';
}
文件b.js路径 -http://127.0.0.1:3000/bar
var a = require('a');
exports.bar = function *() {
this.body = yield a.foo(); // this obviously doesn't work.
}
我希望能够yield a.foo()使用当前上下文 ( this) 并让它像普通路由器调用它一样运行。