【发布时间】:2014-05-18 10:43:23
【问题描述】:
我要做的是将函数中指定的变量设置为某些东西,如果这没有意义,请参见下文。
function getRandomFromArray(arrayName,storeVariable)
{
storeVariable = arrayName[Math.floor(Math.random() * arrayName.length)]
}
var petTypeArray = ['Cat','Dog','Ferret','Spider','Companion Bot'];
getRandomFromArray(petTypeArray,petType)
例如,将 petType 设置为 petTypeArray 中的随机字符串。我做对了吗?我可以这样做吗?
【问题讨论】:
-
为什么不直接使用常规返回值和变量赋值?
标签: javascript function variables arguments