The following program:'use strict' let last = 0 let start_time = Date.now() tick() function get_time() { return Date.now() - start_time } function tick() { const start = get_time() const difference = start - last last = start console.log('start: ', start) while (get_time() < start + 1000) continue console.log('end: ', get_time()) console.log('') setTimeout(tick, 0) } Gives the output:start: 0 end: 1000 start: 1002 end: 2002 start: 3004 end: 4004 start: 5005 end: 6005 start: 7006 end: 8006 Isn't the result supposed to be approximately the following?start: 0 end: 1000 start: 1000 end: 2000 start: 2000 end: 3000 start: 3000 end: 4000 start: 4000 end: 5000
Submitted August 01, 2017 at 02:42PM by IskaneOnReddit
No comments:
Post a Comment