Javascript 将参数传递到setTimeout?

Javascript 将参数传递到setTimeout?,javascript,jquery,settimeout,Javascript,Jquery,Settimeout,目前我正在使用 function showGrowl(lastNumber) { var num = lastNumber; //keep generating a random number untill it is not the same as the lastNumber used while((num = Math.ceil(Math.random() * 3)) == lastNumber); //create a clone of the chosen noti

目前我正在使用

function showGrowl(lastNumber) {
  var num = lastNumber;
  //keep generating a random number untill it is not the same as the lastNumber used 
  while((num = Math.ceil(Math.random() * 3)) == lastNumber);

  //create a clone of the chosen notification
  var clone = $('.notification.n' + num).clone();

  //show the clone
  clone.appendTo('#contain').show('fast', function() {

    //10 seconds after showing, hide the notification
    setTimeout(function() {
      clone.hide('fast', function() {

        //once it is hidden remove it
        clone.remove();

        //then two seconds later show a new notification
        setTimeout(function() {
          showGrowl(lastNumber)
        }, 2000);
      })
    }, 10000);
  });
}

但是,lastNumber在再次调用函数时总是未定义,我需要做什么才能定义lastNumber?

您不必做任何特殊的操作,就可以访问
设置超时中的
lastNumber


但是,我认为您的意思是在
setTimeout
中使用
num
而不是
lastNumber
,lastNumber在这个脚本中永远不会增加或更改,这感觉是错误的