Uncaught ReferenceError: xxx is not defined

writes a function that is referenced on the page and called when the picture is loaded. The function works, but an error is displayed on the console.
when you take that function out to make a demo, you don"t report an error, but when you put it with other js code, you keep reporting an error. I don"t know why. I hope the gods who understand will give us some advice.
Uncaught ReferenceError: AutoResizeImage is not defined

The

code is as follows:
js
/ / Picture proportional scaling

function AutoResizeImage(maxWidth, maxHeight, objImg) {

    var img = new Image();
    img.src = objImg.src;
    var hRatio;
    var wRatio;
    var Ratio = 1;
    var w = img.width;
    var h = img.height;
    wRatio = maxWidth / w;
    hRatio = maxHeight / h;
    if (maxWidth == 0 && maxHeight == 0) {
        Ratio = 1;
    } else if (maxWidth == 0) {//
        if (hRatio < 1) Ratio = hRatio;
    } else if (maxHeight == 0) {
        if (wRatio < 1) Ratio = wRatio;
    } else if (wRatio < 1 || hRatio < 1) {
        Ratio = (wRatio <= hRatio ? wRatio : hRatio);
    }
    if (Ratio < 1) {
        w = w * Ratio;
        h = h * Ratio;
    }
    objImg.height = h;
    objImg.width = w;
}

html

<center><img onerror="this.src="/Content/images/nopic.jpg"" data-src="@BuildEffectImage(effectImage, 0, 625)" src="@ConfigHelper.CdnPrefix/Content/images/NewHome/white.png" class="coverimage" height="625" onload="AutoResizeImage(830, 0, this);"  /></center>

error picture

clipboard.png

Mar.13,2021

it is possible that the js is loaded in the wrong order
put the js before the call

the loading of js involves the problem of loading successively
if the execution is called directly, it needs to be loaded before calling execution
if it is waiting for the page to be loaded, there is no problem for js to load there
js is loaded according to the order of the page code, and the page is loaded from top to bottom

when the browser encounters (embedded) the < script > tag, the current browser has no way of knowing whether javaScript will modify the page content. Therefore, at this point, the browser stops processing the page, executes the javaScript code, and then continues to parse and render the page. The same thing happens when using the src attribute to add to the javaScript (that is, the outer chain javaScript), browser must first take the time to download the code in the outer chain file, and then parse and execute it. In the process, page rendering and user interaction are completely blocked.

that is, whenever the browser parses to the < script > tag (whether embedded or unlinked), the browser downloads, parses, and executes the javaScript code in the tag first, blocking the download and rendering of all subsequent page content.

Menu