js setTimeout 事件与while循环 的作用结合
工具/原料
javascript
方法/步骤
1
var start = new Date;setTimeout(function(){var end = new Date;console.log('Time elapsed:', end - start, 'ms');}, 500);while (new Date - start < 1000) {};执行运算结果。如图:
2
这里console控制台输出两个运算第一个是 1773第二个是 1000为了更形象解析我们先看看这段console出来的结果var start = new Date;console.log('start:',start.getTime(),'ms');setTimeout(function(){var end = new Date;console.log('end:',end.getTime(),'ms');console.log('Time elapsed:', end - start, 'ms');}, 500);while (new Date - start < 1000) {console.log('now:',new Date().getTime(),'ms')};运行结果。如图:
上一篇:《神仙道》与美女子晴促膝夜话
下一篇:IOS开发学习笔记-1