变量重置为默认选项,WHY

Variable reset to default option, WHY?

本文关键字:选项 WHY 默认 变量      更新时间:2023-09-26

我不明白为什么我在变量被分配一个数字后总是以"null"结束。

function evalKayScript(syn){
    coms = extract(syn,"{...}");
    document.write(JSON.stringify(coms));//debug
    for(x in coms){
        ops = extract(coms[x],"(...)");
        com = null; //<-- ***com preset null***
        for(y in funNames){
            if(ops[1] == funNames[y]){
                com = y; //<-- ***com changed to "y"***
            }
        }
        alert(com); <-- alerts given below (first two alerts)
        if(com == null){
            alert("Command ((("+ops[1]+"))) Not Registered!");
            return null;
        }
        exe = funValues[y];
        inputs = execVars(ops[2]);
        inputs = extract(inputs,"[...]");
        for(y in inputs){
            exe.replace(new RegExp("/'('%"+y+"'%')/gim"),inputs[y]);
        }
        exe.replace(new RegExp("/'('%name'%')/gim"),ops[0]).replace(new RegExp("/'('%function'%')/gim"),ops[1]);
        exea = exe;
        if(exe.replace(new RegExp("/':':':javascript/gim"),"")! = exes){ //<-- new invalid ":" error
            eval(exe);
        }else{
            evalKayScript(exe);
        }
    }
}

我不明白为什么,变量"com"变成了一个数字,然后又变成了null…我已经设置了一些错误捕获在我自己的形式,我结束了这些警告:

0 //<-- var com
null //<-- ***var com? this makes no sense, how does it go back to null?***
Command ((("(%name%) already exists!"))) Not Registered! //<--caused by if(com == null) This is normal.

实时脚本位于http://jstone88.bugs3.com/kayscript/file1.html, JS文件位于http://jstone88.bugs3.com/kayscript/kayscript.js

您没有使用RegExp构造函数,因为它应该被使用。

是这样的:

new RegExp("pattern without / at the beginning an end","flags");

/pattern/flags是js中regex的文字形式,但在RegExp构造函数中是不同的。