0

In the javascript course I am learning I am using a node module called passport, to authenticate a user it has some code like this

passport.authenticate("local")(req, res, function()

Now I get normally you could nest functions within the parameters of other functions for call backs, and also keep calling methods on functions but shouldn't the method of this function only take "local" varriable, whats happening here? Would rewritting it as

passport.authenticate("local", req, res, function(){})

achieve the same thing?

Thanks in advance for any help :D

Hunter
  • 13
  • 2
  • 4
    It's equivalent to `let foo = passport.authenticate('local'); foo(req, res, ...)`. – deceze Sep 03 '20 at 13:09
  • `passport.authenticate("local")` calls a function and gets a return value, In this case, apparently the return value is a function, which the code immediately calls by doing `(req, res, function() ...` on it. As @deceze said, it's just like: const tmp = passport.authenticate("local"); tmp(req, res, function() ...` – T.J. Crowder Sep 03 '20 at 13:12
  • See also: [currying](https://stackoverflow.com/questions/36314/what-is-currying) – Jamiec Sep 03 '20 at 13:13

0 Answers0