请问一下: if ( timer ) { clearInterval ( timer ); timer = null; } 和 直接clearInterval ( timer );有什么区别吗?
4 回答
已采纳

摩诃迦叶
TA贡献146条经验 获得超54个赞
if ( timer ) { clearInterval ( timer ); timer = null; } 先判断timer是否为null,然后清除计时器设置,再释放timer占用的资源。
直接clearInterval ( timer );只清除计时器设置
添加回答
举报
0/150
提交
取消