title: Override callback from a function in Javascript
body: <p>Is it possible to override a callback inside a function? </p>
  
  <pre><code>function fn() {
      function cb() {
          console.log("Overriden");
      }
  }
  
  function cb() {
      console.log("Original");
  }
  </code></pre>
  
  <p>As far as I understand, the cb inside the fn becomes a local variable. Hence, when any other functions call cb, they will still get the original function. Is there a way to override the callback?</p>
  
  <p>Edit: Below is the actual code. </p>
  
  <pre><code>module.exports = function(app, passport, async) {
  
      var isLoggedIn = function (req, res, next) {
          if (req.isAuthenticated())
               return next();
          res.redirect('/');
      };
  
      app.get('/info', isLoggedIn, function(req, res) {              
          res.render('info.ejs', {message: req.flash('loginMessage')});
      });
  
      app.post('/add', isLoggedIn, function(req, res) {
          process.nextTick(function() {            
              // do something here
              isLoggedIn = function(req, res, next) {
                  console.log("Modified"); 
              }; 
              res.redirect('/info');
          });         
      });
  }
  </code></pre>