Question: As from the jquery api page
<http://api.jquery.com/jQuery.getScript/>

> 
> Success Callback
> ----------------
> 
> 
> The callback is fired once the script has been loaded but not necessarily executed.
> 
> 
> 
> ```
> $.getScript("test.js", function() {
>     foo();
> });
> 
> ```
> 
> 

if the `foo()` function depend on test.js, it cannot be execute successfully. 

I saw similar thing with google map api but in that case you can specify the callback function in the ajax script url. But in general is there an obvious way to wait until the ajax script executed to do the callback?

Answer: 
`$.getScript(...)` + `setInterval(...)` worked for me:
======================================================

```
$.getScript('https://www.google.com/recaptcha/api.js')
  .done(function() {
    var setIntervalID = setInterval(function() {
      if (window.grecaptcha) {
        clearInterval(setIntervalID);
        console.log(window.grecaptcha);
        letsWorkWithWindowDotGreptcha();
      };
    }, 300);
  });

  function letsWorkWithWindowDotGreptcha() {
    // window.greptcha is available here....
  }

```

Once the `variable` we are looking for is defined (in my case `window.grecaptcha`, i can call a `closure function` which can be `abstracted out`. 

Good Luck...
I'm afraid the solution requires polling for the dependency. Alternatively the script needs to be wrapped in a pre-defined callback like AMD.