javascript - Call function with no argument and no default argument defined -


from example here:

app.get('/account', ensureauthenticated, function(req, res){     res.render('account', { user: req.user }); });  function ensureauthenticated(req, res, next) {     if (req.isauthenticated()) { return next(); }     res.redirect('/login') } 

i don't understand how ensureauthenticated works. requires 3 arguments, no default argument set. if call no argument (in app.get), execute correctly, how be?

you're not calling ensureauthenticated anywhere in code; you're passing reference function, , http framework calls function later (when request made /account) passing correct arguments.

if had written ensureauthenticated() (with parentheses), you'd calling no parameters. without parentheses, you're passing reference function.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -