【问题标题】:Min Max function bugs in illustrator javascript/extendscript?illustrator javascript/extendscript 中的 Min Max 函数错误?
【发布时间】:2011-07-30 10:37:34
【问题描述】:

有人可以解释为什么以下代码在 Safari/Javascript 和 Illustrator/ExtendScript 中返回不同的结果吗?

在我的测试中,浏览器版本似乎按预期工作。插画师不多。这是一个真正的错误吗?或者只是 ExtendScript(Adobe 的 Creative Suite 应用程序的 Javascript 实现)和 apply 方法的问题?

function testMinMax(){
    var testArray = [2,1,7,3,6,7,8,23,45,26,13,9];

    function getMinOfArray(numArray) {
      return Math.min.apply(Math, numArray);    
    }

    function getMaxOfArray(numArray) {
      return Math.max.apply(Math, numArray);
    }

    alert ("min [" + getMinOfArray(testArray) + "] of " + testArray);
    alert ("max [" + getMaxOfArray(testArray) + "] of " + testArray);

    // Expected Values:
    // min [1] of 2,1,7,3,6,7,8,23,45,26,13,9
    // max [45] of 2,1,7,3,6,7,8,23,45,26,13,9

    // Illustrator Scripting returns the following values
    // min [1] of 2,1,7,3,6,7,8,23,45,26,13,9
    // max [9] of 2,1,7,3,6,7,8,23,45,26,13,9   
}

// Call the test case
testMinMax();

【问题讨论】:

    标签: javascript adobe-illustrator extendscript


    【解决方案1】:

    我遇到了类似的问题。看到你的帖子(我唯一能找到的)后,我不得不想出这个解决方法;

    var varSourceArray=[varSource_R, varSource_G, varSource_B]
    varSourceArray.sort()
    
    varSource_Min = varSourceArray[0];
    varSource_Max = varSourceArray[2];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-01
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多