当我将其传递给函数时,参数显示为未定义

时间:2013-07-22 16:18:16

标签: javascript undefined

我添加了断点,当我传递一个变量时,似乎tempTime变得不确定。只有在调用delayer时才会成为数字。我不知道它为什么这样做,我不知道如何解决它。

Javascript代码

 var executionTime;
 var initialTime = localStorage.getItem("initialTime");


 if(initialTime == "null")
 {

 }
 else
 {
    var tempDate = new Date().getTime(); 
    executiontime = 30000-(tempDate- parseInt(initialTime, 10));
    if (executionTime<0) 
    {
    executionTime = 0;
    }  
    showPopUp(executionTime); //executionTime has a number when I call the function                        `//butshows up as undefined in the showPopUp function`
 }





 function showPopUp(tempTime){
  var initialTime = localStorage.getItem("initialTime");
  var executionTime = tempTime;

  if(initialTime== "null")
  {
    executionTime = 20000;
  }

  localStorage.setItem("initialTime", (new Date()).getTime());
  setTimeout(function() {
  showAlert();
  localStorage.setItem("initialTime", null);}, executionTime);
 }

  function delayer(){ 
  showPopUp(20000); //not undefined when called
  }

  function showAlert(){
   alert("Warning");
  }

1 个答案:

答案 0 :(得分:1)

executiontime = 30000-(tempDate- parseInt(initialTime, 10));
showPopUp(executionTime);                      
你正在使用两种不同的案例 及时利用你的资本 javascript区分大小写。