0

I'm currently coding up an application that will have one view come up and then upon its completion will have another view come up. My current code looks something like this:

        Controller.startMove("view1", true, true);
        Controller.startMove("view2", true, true);

StartMove is a function that will take the view and show it while also implementing the functionality of the call. the second and third parameters are flags for other things not pertaining to this issue. My question is this; How do I "wait" for the first function to finish before doing the second? Right now if I have both up, it doesn't know which view to show and goes crazy.

1
  • you will need to edit the Controller.startMove method to handle callback Commented Feb 25, 2014 at 5:00

1 Answer 1

2

The typical pattern in JavaScript is to provide a callback function to an asynchronous function call. When the async call is complete then the callback will be executed.

For example:

Controller.startMove("view1", true, true, function() {
  Controller.startMove("view2", true, true, function() {
    // Done moving here.
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

+1 The problem using anonymous functions though is that you can end up with quite a nesting level. If more than 2-3 I would recommend defining named functions in main scope and call them instead. Just my 2 cents..

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.