Calling functions outside paths
Posted
by
user1775718
on Stack Overflow
See other posts from Stack Overflow
or by user1775718
Published on 2012-11-01T16:17:13Z
Indexed on
2012/11/01
17:01 UTC
Read the original article
Hit count: 213
In mongojs, when you do:
var birds = db.birds.find(searchTerm, callback);
...how do you pass arguments to the callback? I've tried bind, as in:
birds = db.birds.find(searchTerm, app.get('getBirds').bind(res));
...but to no avail. Just fyi I'm trying to pass the response object of the GET route so that the callback can render using res.send(results).
The other option is to set app.set('res': res); and call app.get('res') from the callback - I'm not sure this is a good idea. It works, but it doesn't obey the events loop model too well - I think the request back to the app may be costly? Any help would be gratefully accepted. :)
© Stack Overflow or respective owner