【发布时间】:2016-01-22 15:49:08
【问题描述】:
我是 Javascript 和 AngularJS 以及 Web 开发的新手,在查看 Angular docs on directives 时,我遇到了这段代码:
// start the UI update process; save the timeoutId for canceling
timeoutId = $interval(function() {
updateTime(); // update DOM
}, 1000);
为什么不能这样写:
// start the UI update process; save the timeoutId for canceling
timeoutId = $interval(updateTime(), 1000);
这样不还是回调函数吗?它仍然是函数中的函数。在函数中包含函数有什么意义……在函数中?
【问题讨论】:
-
你的意思可能是
$interval(updateTime, 1000),现在updateTime的方式是立即调用,而不是在1秒之后 -
@AndrewWhitaker 我不知道有什么区别,谢谢!
标签: javascript angularjs function callback