【问题标题】:Variable reset to default option, WHY? [closed]变量重置为默认选项,为什么? [关闭]
【发布时间】:2014-05-06 13:40:13
【问题描述】:

我不明白在为变量分配一个数字后,我是如何一直以“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 的实时脚本,http://jstone88.bugs3.com/kayscript/kayscript.js 的 JS 文件

【问题讨论】:

  • 第二次循环中似乎没有匹配的funNames[y]
  • com = null;com 设置为null 在每次迭代中。我不清楚你的问题。
  • ?但这没有意义,funNames中只有一个预设功能,肯定缺少我没有看到的东西,而@Felix King,它应该只通过一次,因为我正在进入,{(output)(custom)([document.write(\"(%0%)\");][:::javascript])} .并且com = null; 设置在为其分配新值的循环之前。
  • 所以你是说coms 只包含一个属性?您对此 100% 确定吗?
  • 是的,@Amit Joki 给了我一个修复,我现在只有一个无效的 ":"。

标签: javascript customization


【解决方案1】:

您没有使用应该使用的 RegExp 构造函数。

是这样的:

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

/pattern/flags是在js中写正则表达式的字面形式,但在RegExp构造函数中是不同的。

【讨论】:

  • 谢谢,我的初始脚本中的正则表达式错误,不是我遇到的常见问题,导致我使用正则表达式,它说“:”无效。
  • 你原来的正则表达式是什么?
  • /\:\:\:javascript/gim @Amit Joki
  • 你不需要转义:。只需使用:::javascript/gim
  • 仍然说无效的“:”。 @Amit Joki
猜你喜欢
  • 1970-01-01
  • 2017-01-24
  • 2018-05-06
  • 2012-08-14
  • 1970-01-01
  • 2011-10-08
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多