Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript作用域错误问题_Javascript_Timer_Scope_Closures_Object Literal - Fatal编程技术网

Javascript作用域错误问题

Javascript作用域错误问题,javascript,timer,scope,closures,object-literal,Javascript,Timer,Scope,Closures,Object Literal,我写了这个启动计时器的代码。我启动一个函数,当计时器达到0时重新启动它。它可以工作,但是我在控制台中得到一个错误,它说UncaughtTypeError:Cannotread属性'restartTimer'为undefined。这与此有关 timer=utility.math.surveyTimer({ 秒:时间, onUpdateStatus:功能(剩余时间){ $(surveyTimerNode).text(剩余时间); }, 重启计时器:函数(){ window.TimerInterva

我写了这个启动计时器的代码。我启动一个函数,当计时器达到0时重新启动它。它可以工作,但是我在控制台中得到一个错误,它说UncaughtTypeError:Cannotread属性'restartTimer'为undefined。这与此有关

timer=utility.math.surveyTimer({
秒:时间,
onUpdateStatus:功能(剩余时间){
$(surveyTimerNode).text(剩余时间);
},
重启计时器:函数(){
window.TimerInterval=timer.start();
},
onCounterEnd:函数(){
if(utility.bool.isQuestionScreen()){
if(utility.bool.surveyWillLoop()){
data.setPersistentSurveyData(“DSM\U调查屏幕”,调查屏幕);
data.setPersistentSurveyData('DSM_SURVEY_SCREEN_ORDER',SurveyScreender);
tagData=data.getPersistentSurveyData('DSM_SURVEY_data');
apiParam=api.helper.buildAPIParam('surveyTimeout',tagData);
api.post.postToAPI(apiParam);
parent.resetSurveyProgress();
parent.moveToNextScreen();
此参数为.restartTimer();
}否则{
parent.goToEndscreen();
}
}
}
});

window.TimerInterval=timer.start()
只是猜测,但我认为您在选项对象中使用的
this
不是您认为的
this

尝试更改surveyTimer的实现,它当前位于:

counterEnd();
致:


感谢Steve的输入,但是这样做会阻止计时器重新启动。当我添加代码时,不会。错误会消失。但我认为这是因为没有调用该方法。
counterEnd.call(options);