0

有人可以解释为什么以下代码在 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();
4

1 回答 1

1

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

var varSourceArray=[varSource_R, varSource_G, varSource_B]
varSourceArray.sort()

varSource_Min = varSourceArray[0];
varSource_Max = varSourceArray[2];
于 2011-12-21T22:14:02.573 回答