- i am new to js
- I thought closure as inner function as access to variables in outer function.
- but in the below code if separate function has access to another separate function will it form closure
function auth(name) {
return function (req, res, next) {
if (req.isAuthenticated() && name && req.user.name === name) next();
else if (req.isAuthenticated() && !name) next();
else res.send(401);
};
}
app.get('/example/a', auth(), function (req, res) {
res.send('Hello from A!');
});
app.get('/example/b', auth('Francis'), function (req, res) {
res.send('Hello from B!');
});
via texi rv
No comments:
Post a Comment