1

I have the following code (simplified):

function(req, res) {
  var path = 'login';

  req.on('end', function(data) {
    var post = parsevars(rawpost, '&');
    if (typeof post.username !== 'undefined' && typeof post.password !== 'undefined') {
      if (handlelogin(post.username, post.password))
        path = req.url;
    }
  });
}

The bold part is what doesn't work as expected :/
Any input on how to escape this scope restriction would be great.

1
  • and what is the expected behavior? do you leak the path in some other closures where you expect it to change when the end fires? otherwise I don't see how it would matter for the outer function that declared it. Commented Apr 28, 2012 at 19:45

2 Answers 2

2

It DID work, the code after it was just executed BEFORE the event handler.

Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to the async world :)
0

Odd, that should work since req is in the outer scope of the closure.

However I think you'll find that the current req is also available as this within the callback, i.e.:

path = this.url;

1 Comment

Like your edit says, this should work, I very much doubt changing the name of the reference will have an effect. In fact, if it does we should be more worried. Most likely cause: The OP's bug, although with zero information there's not much that can be done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.