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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -