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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -