0

I have a function that returns some data. The function needs to utilize another function from a different file, and to do this, I have a .getScript() running inside of it:

foo() {
    var bar;
    $.getScript("bar.js", function() {
          bar = FooBar.fooBar()
    });
    return bar;
}

The function foo() is used inside of another function, bar(). For bar() to properly continue, it needs the information that foo() returns. But it always returns null (when printed, it is undefined because I am not waiting for .getScript() to finish. If I put a console.log(bar) inside of the getScript, it prints after some time (a couple of seconds). How do I make my function foo() not return anything before getScript is done?

user3026388
  • 300
  • 2
  • 12

0 Answers0