除了 jQuery,我对 JavaScript 还很陌生,我正在阅读 JavaScript 数组中的随机化以及使用带有随机数的 Array.sort 方法的缺点。我看到的建议是使用 Fisher-Yates shuffle。在查看此方法的 JavaScript 代码时:
Array.prototype.randomize = function()
{
var i = this.length, j, temp;
while ( --i )
{
j = Math.floor( Math.random() * (i - 1) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
}
我被这行打动了:
var i = this.length, j, temp;
这里发生了什么?一个变量是否被赋予了多个值,或者这是某种东西的简写?