Question: I would like to get the code below to wait for another script to be loaded before executing. How can I get this to wait for sp.js to load before executing?

```
$.getScript("/sites/MySite/SiteAssets/jquery.LISP.Quicklaunch.js", function(){});

jQuery(document).ready(function() {
jQuery('#s4-leftpanel').quicklaunchHide({
    collapseImage: '/_layouts/images/mewa_leftPage.gif',
    expandImage: '/_layouts/images/mewa_rightPage.gif',
    prependLocation: '.s4-tn',
    mainDiv: '.s4-ca',                            
    leftMargin: 0,    
    hideOnDefault: true,   
    allowCookie: true,
    cookieName: 'quicklaunchStatus'            
});

function setHeight() {
    windowHeight = $(window).innerHeight();
    $('#s4-mainarea').css('min-height', windowHeight-203);
};
setHeight();

$(window).resize(function() {
    setHeight();
});

jQuery('#s4-workspace').css('cssText', 'height: 262px !important');
});

```

Answer: 
I ended up doing it this way:

```
$.getScript("/sites/MySite/SiteAssets/jquery.LISP.Quicklaunch.js", function(){});

jQuery(document).ready(function() {
    ExecuteOrDelayUntilScriptLoaded(delayedExecute, "sp.js");
});

function delayedExecute(){
    jQuery('#s4-leftpanel').quicklaunchHide({
        collapseImage: '/_layouts/images/mewa_leftPage.gif',
        expandImage: '/_layouts/images/mewa_rightPage.gif',
        prependLocation: '.s4-tn',
        mainDiv: '.s4-ca',                            
        leftMargin: 0,    
        hideOnDefault: true,   
        allowCookie: true,
        cookieName: 'quicklaunchStatus'            
    });

    function setHeight() {
        windowHeight = $(window).innerHeight();
        listHeight = windowHeight - 180;
        jQuery('#s4-workspace').css('cssText', 'height: ' + listHeight + 'px !important');
    };
    setHeight();

    $(window).resize(function() {
        setHeight();
    });
};

```
Deferring execution of code is most simply done using a callback. For instance, if you have a function called `defer()` which you only want to execute after a function `dofirst()` has executed, you'd do this:

```
function dofirst(arguments, callback){
    //Do something here first, then call the callback
    callback();
};

function defer(arguments){
    //This is the code which you want to defer until the dofirst code has executed
    return;
}

//Invoke the function here
dofirst(arguments, defer);

```

hope this helps!