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: 
As mentioned `then`, `done` and the `$.getScript` callback fire when the script was loaded and not executed wich may be to early … intervals may be a way of tackling this but in my opinion it seems not very elegant.

My solution is triggering an event inside the async loaded script like:

```
jQuery( document ).trigger( 'loadedeventsjs' );

```

And inside my main script i could bind to that event like:

```
jQuery( document ).on( 'loadedeventsjs', function() {

    jQuery( '#mainmenu_wrapper' ).on( 'swiperight', menuout );

} );

```
$getScript use like this

```
$.getScript( "js/jquery.raty.min.js" )
    .done(function( script, textStatus ) {
          console.log( textStatus );
         }
          });

```

this is working fine for me