javascript - Why method passed as argument wont work here -


i have code in node/express api. works

router.get('/auth',function(req, res, next){    var callback = function(redirecturl){     return res.redirect(redirecturl);   }    auth.beginoauth(callback);  }); 

but if modify code this. not work -

router.get('/auth',function(req, res, next){    auth.beginoauth(res.redirect);  }); 

why when method passed directly, wont work?

could execution context different.

when res.redirect(redirecturl), this inside redirect method referring res object(unless custom execution context used), when pass res.redirect callback, when callback invoked context lost.

router.get('/auth',function(req, res, next){        auth.beginoauth(res.redirect.bind(res)); }); 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -