これが関数のスニペットです。各画像の元のサイズを取得しています。次に、単純なifステートメントを実行したいのですが、変数'imageWidth'にアクセスできません。'theImage.onload = function()'の外で'undefined'を取得します。なぜそれは範囲外ですか?
    var parentWidth = $('figure.pack_image').width();
    var screenImage = $('figure.pack_image img');
    var imageWidth = '';
    screenImage.each(function () {
        var theImage = new Image();
        theImage.src = $(this).attr('src');
        theImage.onload = function() {
            imageWidth = this.width;
        }
        if (imageWidth > parentWidth) {
        ...