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
Post a Comment