我是新来的JavaScript和AngularJS,以及网络的发展,而我正在经历的Angular docs on directives,我碰到这段代码传来:在javascript中将函数放入其他空函数的目的是什么?
// 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我不知道有什么区别,谢谢! – pv93