JavaScript error: “is not a function”

前端 未结 3 1207
太阳男子
太阳男子 2020-12-03 13:18

It looks like \"$smth is not a function\" is a very common problem with JavaScript, yet after looking through quite a few threads I still cannot understand what is causing i

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 13:51

    Your LMSInitialize function is declared inside Scorm_API_12 function. So it can be seen only in Scorm_API_12 function's scope.

    If you want to use this function like API.LMSInitialize(""), declare Scorm_API_12 function like this:

    function Scorm_API_12() {
    var Initialized = false;
    
    this.LMSInitialize = function(param) {
        errorCode = "0";
        if (param == "") {
            if (!Initialized) {
                Initialized = true;
                errorCode = "0";
                return "true";
            } else {
                errorCode = "101";
            }
        } else {
            errorCode = "201";
        }
        return "false";
    }
    
    // some more functions, omitted.
    }
    
    var API = new Scorm_API_12();
    

提交回复
热议问题