【发布时间】:2020-02-15 23:26:21
【问题描述】:
我有一个函数,它有一个必需参数和可变数量的参数。我正在将一组 blob 传递给函数。该函数的简化版本如下所示:
function test(directory, blob0, blob1) {
for (var argumentIndex = 1; argumentIndex < arguments.length; argumentIndex++) {
var bytes = arguments[argumentIndex].getBytes();
//do some things
}
}
我正在使用 rhino 运行时,所以我不能使用扩展运算符。我最接近的方法是使用 apply 函数,但我不确定如何在上面的测试函数中传递所需的参数(目录)。
var blobs = [];
blobs[0] = getBlob();
blobs[1] = getBlob();
blobs[2] = getBlob();
test.apply(null,blobs) //doesn't set required parameter (directory)
【问题讨论】:
-
我使用的是 rhino 运行时为什么?
-
@TheMaster 只是过于谨慎,因为 Google 最近进行了迁移,我不想花时间追踪潜在的错误。并不是说这些是相关的,但有趣的是最近有一个使用 GAS 设置和获得保护的错误。见这里:issuetracker.google.com/issues/148894990
-
但这也会影响犀牛。不是吗?在某种程度上,无论您是否迁移,您都会受到影响。
标签: javascript google-apps-script