I have some code:
$(function(){
    function foo() {
     var elem = $('.some-dom-elem');
     console.log(elem);
    }
    location.reload = function() {
     foo(); // returns undefined
    }
});
And here is the same code with the addition of an extra jQuery ready function:
$(function(){
    function foo() {
        var elem = $('.some-dom-elem');
        console.log(elem);
    }
    location.reload = function() {
        $(function(){
            foo(); // returns DOM element
        });
    }
});
Why do I need the extra jQuery ready function in the second code sample in order to make my foo function not return undefined?
