0

这是 Adob​​e ExtendScript 的 javascript。基本上我想在脚本中有一个持久变量来存储用户的偏好,就像你可以使用 AppleScript 一样property。我能想到的唯一方法是让脚本用File.write().

var MY_PROPERTY = true;

function reassignProperty(propName, propValue) {
    var thisFile = new File($.fileName);

    if (thisFile.open("r")) {
        var myScript = thisFile.read();
        thisFile.close();

        // Look for the property declaration and overwrite with new value
        var searchStr = new RegExp("(var " + propName + " = )" + ".+");
        var newScript = myScript.replace(searchStr, "$1" + propValue + ";");

        thisFile.open("w");
        thisFile.write(newScript);
        thisFile.close();
    }
}

reassignProperty("MY_PROPERTY", "false");

据我所知,这行得通。但它安全吗?我的直觉告诉我应该有一种更简洁的方式来拥有持久变量,但如果没有,我只想知道自覆盖脚本是否存在任何潜在问题。

4

2 回答 2

0

I am not familiar with Adobe ExtendScript, but usually you would store the user's preferences in a separate file and then read that file when the program starts.

于 2011-04-01T18:30:04.410 回答
0

几乎可以肯定的是,包含程序自我替换的能力将是一个糟糕的设计决策。首先你会遇到困难,因为当前的执行线程与应该运行的文件不同,所以你肯定会得到副作用。

基本上你要求混淆,而混淆是不好的。您应该使用外部文件来存储数据,或者只是将信息保存在 HTML 的变量或字段中。

于 2011-04-01T19:06:42.457 回答