我试图在函数中传递它们并放入数组但结果。我想不出任何解决方案。这是结果:
我想要的是这样的
[4,4,5,4]
但输出是
[4, 4, 4, 4]
[4, 4, 4, 4]
[5, 5, 5, 5]
[4, 4, 4, 4]
$("#machine1").slotMachine({
active : 0,
delay : 500,
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);
$("#machine2").slotMachine({
active : 0,
delay : 700,
direction: 'down',
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);
$("#machine3").slotMachine({
active : 0,
delay : 900,
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);
$("#machine4").slotMachine({
active : 0,
delay : 1100,
direction: 'down',
randomize : function(activeElementIndex){
var activeElementIndex = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
//console.log(activeElementIndex);
call_me(activeElementIndex);
return activeElementIndex;
}
}).shuffle(5);
function call_me(wait){
var nice = [];
for(var i = 0; i < 4; i++){
nice[i] = wait;
}
console.log(nice);
}
答案 0 :(得分:1)
在任何函数之外定义nice[]
数组并切换:
call_me(activeElementIndex) > nice.push(activeElementIndex)