node.js - How to access koa context in another generator function? -
in koa can accesss koa context in first generator function via this
:
app.use(function *(){ this; // context }
but if yield generator function can't access context via this
anymore.
app.use(function *(){ yield mygenerator(); } function* mygenerator() { this.request; // undefined }
i've been able pass context sec generator function, wondering whether there's cleaner way access context.
any ideas?
either pass this
argument said:
app.use(function *(){ yield mygenerator(this); }); function *mygenerator(context) { context.request; }
or utilize apply()
:
app.use(function *(){ yield mygenerator.apply(this); }); function *mygenerator() { this.request; }
node.js koa
No comments:
Post a Comment