Google 应用程序 javascript 解释器因用户定义函数中的数组参数而失败

Google Apps javascript interpreter failed with an array parameter in a user defined function

这个在GoogleSheet的脚本编辑器里写的微不足道的功能,失败了!

function Long(my_array)
{
  Logger.log(my_array.length)
}

 Long([1,2,3]); // => TypeError: Impossible to read property "length" from undefined.**

与 Google 脚本解释器仍然存在相同的错误,即使 没有 执行函数调用:

函数长(my_array){ return my_array.length}

// => 类型错误:无法读取属性 "length",因为未定义。第 2 行

当然,任何正确的Javascript解释器都不会失败。

当使用 Google 的脚本编辑器时,运行 操作将执行脚本中定义的功能之一(可以在 旁边看到一个下拉菜单运行 调试 按钮)。 selected 函数必须是 Long 本身,它是在没有参数的情况下调用的。

相反,只需在 运行ning:

之前创建一个新函数并 select 它
function Long(my_array)
{
  Logger.log(my_array.length)
}


function myFunction() {
  Long([1,2,3,4]);
}