Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Aug 24, 2017
1 parent b13f607 commit 456c739
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ function _runMiddlewares (err, req, res) {
```
<a name="keep-context"></a>
#### Keep the context
If you need it you can also keep the context of the calling function by calling `run` with `run.call(this, req, res)`, in this way you can avoid closures allocation.
If you need it you can also keep the context of the calling function by calling `run` with `run(req, res, this)`, in this way you can avoid closures allocation.

```js
http
.createServer(function handler (req, res) {
middie.run.call({ context: 'object' }, req, res)
middie.run(req, res, { context: 'object' })
})
.listen(3000)

function _runMiddlewares (err, req, res) {
function _runMiddlewares (err, req, res, ctx) {
if (err) {
console.log(err)
res.end(err)
return
}
console.log(this.context)
console.log(ctx)
}
```

Expand Down

0 comments on commit 456c739

Please sign in to comment.