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