Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39068 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2020-10-31 13:26 -0700 |
| Last post | 2020-11-01 16:19 -0800 |
| Articles | 15 on this page of 35 — 6 participants |
Back to article view | Back to comp.lang.javascript
Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:26 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:37 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:41 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 13:54 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-10-31 17:51 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? luserdroog <luser.droog@gmail.com> - 2020-10-31 23:43 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 00:18 -0700
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 13:47 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:11 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:15 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:21 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-01 09:52 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 11:27 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 11:33 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-01 15:42 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-11-08 23:36 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Silvio <silvio@internet.com> - 2020-11-09 17:01 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 11:37 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:17 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 14:08 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 01:09 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:09 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 14:07 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 01:11 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 16:18 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 11:37 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 09:28 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-01 21:22 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 14:10 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 01:04 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-01 16:16 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Arno Welzel <usenet@arnowelzel.de> - 2020-11-02 11:40 +0100
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-11-11 00:21 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-11 09:13 -0800
Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-11-01 16:19 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-02 01:09 +0100 |
| Message-ID | <i09114FsckrU1@mid.individual.net> |
| In reply to | #39096 |
Jonas Thörnvall: > Den söndag 1 november 2020 kl. 21:17:32 UTC+1 skrev Arno Welzel: >> Jonas Thörnvall: >> >> [...] >>> Here is an example using setInterval 0 ms can you say why it run 1000-10000 times slower then if just run thru a loop. >> >> Why do you expect that setInterval() with 0 ms will cause code to run >> with no delay at all? >> >> Even with 0 ms there is overhead to trigger the interval handler. Of >> course this is slower than just running something without any delay in a >> loop. >> >> >> -- >> Arno Welzel >> https://arnowelzel.de > > Yeah i could accept 100 times overhead, but not 1000-100 000 something is wrong. How did you calculate this factor exactly? -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-01 21:09 +0100 |
| Message-ID | <i08j0eFpi7mU2@mid.individual.net> |
| In reply to | #39083 |
Jonas Thörnvall: [...] > I am fully aware of Javascripts drawing/animation capabilities used it for a few projects. > > That is not the problem, the problem is its capabilities when it come to poll values from the UI. It hogs the processor and makes running calculations some 1000 to 10 000 times slower. Whatever "poll values from the UI" means. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-01 14:07 -0800 |
| Message-ID | <2c544c3a-2dea-472e-87cb-9578fd09072bo@googlegroups.com> |
| In reply to | #39092 |
Den söndag 1 november 2020 kl. 21:10:00 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > [...] > > I am fully aware of Javascripts drawing/animation capabilities used it for a few projects. > > > > That is not the problem, the problem is its capabilities when it come to poll values from the UI. It hogs the processor and makes running calculations some 1000 to 10 000 times slower. > > Whatever "poll values from the UI" means. > > > -- > Arno Welzel > https://arnowelzel.de Well isn't that what you do pull values or push values using a timer periodically? I do not like anal ENTP lingo, and have no inclination to learn catch phrases to make people happy. Natural language describing processes, is what is preferable.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-02 01:11 +0100 |
| Message-ID | <i0914uFsckrU2@mid.individual.net> |
| In reply to | #39095 |
Jonas Thörnvall: > Den söndag 1 november 2020 kl. 21:10:00 UTC+1 skrev Arno Welzel: >> Jonas Thörnvall: >> >> [...] >>> I am fully aware of Javascripts drawing/animation capabilities used it for a few projects. >>> >>> That is not the problem, the problem is its capabilities when it come to poll values from the UI. It hogs the processor and makes running calculations some 1000 to 10 000 times slower. >> >> Whatever "poll values from the UI" means. >> >> >> -- >> Arno Welzel >> https://arnowelzel.de > > Well isn't that what you do pull values or push values using a timer periodically? No, this is "using a timer periodically". This can of course not be faster as the timer runs. If the timer is set to run something every 4ms you get 250 runs per minute - this is not because of JavaScript being so slow, but the timer does not trigger the run more often. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-01 16:18 -0800 |
| Message-ID | <ef2a736b-6fbf-4e97-b44e-c5c8ea86b7f4o@googlegroups.com> |
| In reply to | #39101 |
Den måndag 2 november 2020 kl. 01:11:18 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > > Den söndag 1 november 2020 kl. 21:10:00 UTC+1 skrev Arno Welzel: > >> Jonas Thörnvall: > >> > >> [...] > >>> I am fully aware of Javascripts drawing/animation capabilities used it for a few projects. > >>> > >>> That is not the problem, the problem is its capabilities when it come to poll values from the UI. It hogs the processor and makes running calculations some 1000 to 10 000 times slower. > >> > >> Whatever "poll values from the UI" means. > >> > >> > >> -- > >> Arno Welzel > >> https://arnowelzel.de > > > > Well isn't that what you do pull values or push values using a timer periodically? > > No, this is "using a timer periodically". This can of course not be > faster as the timer runs. If the timer is set to run something every 4ms > you get 250 runs per minute - this is not because of JavaScript being so > slow, but the timer does not trigger the run more often. > > > > -- > Arno Welzel > https://arnowelzel.de Yeah... So how did you mean i should use setTimeout and setInterval.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-02 11:37 +0100 |
| Message-ID | <i0a5qfF52nrU1@mid.individual.net> |
| In reply to | #39103 |
Jonas Thörnvall: [...] > Yeah... So how did you mean i should use setTimeout and setInterval. You should not do anything just because someone tells you to do so. First you should understand what an event driven UI is and that JavaScript is not multithreaded. If your application needs to do something periodically but also should handle user input, you have only two choices in JavaScript: Use setInterval() or setTimeout() to keep things going by calling some function which keeps the background stuff running by executing only one thing at a time for each timer trigger so the browser still can pass events to the event handlers. As in <https://arnowelzel.de/en/projects/example-for-webgl> there is an animation running constantly but at the same time user input is possible as well to enable full screen view or stop and reset the animation. OR: Use workers (see <https://developer.mozilla.org/en-US/docs/Web/API/Worker>) to start a script as background process. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-01 09:28 -0800 |
| Message-ID | <84d6ebe8-9a2c-4d91-875f-54f98b5e27b8o@googlegroups.com> |
| In reply to | #39077 |
Den söndag 1 november 2020 kl. 13:47:52 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > > Den söndag 1 november 2020 kl. 07:43:43 UTC+1 skrev luserdroog: > >> On Saturday, October 31, 2020 at 7:51:30 PM UTC-5, Jonas Thörnvall wrote: > >> > >>> Well i am done. > >>> https://jonasth.github.io/random.html > >> > >> Did you figure out what the problem was? > > > > Yeah Javascript is really not suited for handling UI updated in realtime. It simply not possible to run loops "stop them" and update the UI in realtime. > > No, it's just you who is not able to deal with it. > > Example: <https://arnowelzel.de/en/projects/example-for-webgl> > > How do you think are all games done using JavaScript and HTML5? > > > At least not in an efficient manner that make sense. Probably it should be possible to do in much more efficient way, by some polling technc. I can't simply see how setInterval can cause so much lag as it does. > > Define "lag". Depending on the capabilities of the browser and the > hardware used the example above renders an animation of a 3D model at > the exact refresh rate of your display. And this is all done in > JavaScript and as soon as one clicks and drags inside the animation it > stops and follows the mouse. > > > -- > Arno Welzel > https://arnowelzel.de I do not know how Javascript resolving it being single threaded, but i slightly remember some technic called polling. It seem javascript polling tecknic to UI maybe do to many calls out? I could accept a hundred times slower, like polling values every 1/100 of second but 1000 to 100 000 times slower seem ridiculous.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-01 21:22 +0100 |
| Message-ID | <i08jo8FpoofU1@mid.individual.net> |
| In reply to | #39085 |
Jonas Thörnvall: [...] > I do not know how Javascript resolving it being single threaded, but i slightly remember some technic called polling. It seem javascript polling tecknic to UI maybe do to many calls out? I could accept a hundred times slower, like polling values every 1/100 of second but 1000 to 100 000 times slower seem ridiculous. "Polling" means to actively read values instead of reacting to an event or message. And yes, JavaScript can "poll" values from the UI very fast. However: setInterval() will *not* work with 0ms. The delay will usually be limited to a minium value as it makes no sense to constantly fire an event handler without any delay. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-01 14:10 -0800 |
| Message-ID | <2b5e551d-6a60-48e1-9ade-a8f693709ee7o@googlegroups.com> |
| In reply to | #39094 |
Den söndag 1 november 2020 kl. 21:22:41 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > [...] > > I do not know how Javascript resolving it being single threaded, but i slightly remember some technic called polling. It seem javascript polling tecknic to UI maybe do to many calls out? I could accept a hundred times slower, like polling values every 1/100 of second but 1000 to 100 000 times slower seem ridiculous. > > "Polling" means to actively read values instead of reacting to an event > or message. And yes, JavaScript can "poll" values from the UI very fast. > > However: setInterval() will *not* work with 0ms. The delay will usually > be limited to a minium value as it makes no sense to constantly fire an > event handler without any delay. > > -- > Arno Welzel > https://arnowelzel.de I do not think you understand the problem or i totally do it backward, tell me which.... The timer doing no polls it doing function call using intervals to flip coins got it??????
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-02 01:04 +0100 |
| Message-ID | <i090p1Fs8rhU3@mid.individual.net> |
| In reply to | #39097 |
Jonas Thörnvall: > Den söndag 1 november 2020 kl. 21:22:41 UTC+1 skrev Arno Welzel: >> Jonas Thörnvall: >> >> [...] >>> I do not know how Javascript resolving it being single threaded, but i slightly remember some technic called polling. It seem javascript polling tecknic to UI maybe do to many calls out? I could accept a hundred times slower, like polling values every 1/100 of second but 1000 to 100 000 times slower seem ridiculous. >> >> "Polling" means to actively read values instead of reacting to an event >> or message. And yes, JavaScript can "poll" values from the UI very fast. >> >> However: setInterval() will *not* work with 0ms. The delay will usually >> be limited to a minium value as it makes no sense to constantly fire an >> event handler without any delay. >> >> -- >> Arno Welzel >> https://arnowelzel.de > > I do not think you understand the problem or i totally do it backward, tell me which.... > > The timer doing no polls it doing function call using intervals to flip coins got it?????? Yes - but you tried to use setInterval() with a delay of 0ms to keep a function running to poll to UI and then complained that JavaScript is slow when polling the UI. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-01 16:16 -0800 |
| Message-ID | <112d2238-4adb-419c-b4da-25db9e60391bo@googlegroups.com> |
| In reply to | #39099 |
Den måndag 2 november 2020 kl. 01:04:59 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > > Den söndag 1 november 2020 kl. 21:22:41 UTC+1 skrev Arno Welzel: > >> Jonas Thörnvall: > >> > >> [...] > >>> I do not know how Javascript resolving it being single threaded, but i slightly remember some technic called polling. It seem javascript polling tecknic to UI maybe do to many calls out? I could accept a hundred times slower, like polling values every 1/100 of second but 1000 to 100 000 times slower seem ridiculous. > >> > >> "Polling" means to actively read values instead of reacting to an event > >> or message. And yes, JavaScript can "poll" values from the UI very fast. > >> > >> However: setInterval() will *not* work with 0ms. The delay will usually > >> be limited to a minium value as it makes no sense to constantly fire an > >> event handler without any delay. > >> > >> -- > >> Arno Welzel > >> https://arnowelzel.de > > > > I do not think you understand the problem or i totally do it backward, tell me which.... > > > > The timer doing no polls it doing function call using intervals to flip coins got it?????? > > Yes - but you tried to use setInterval() with a delay of 0ms to keep a > function running to poll to UI and then complained that JavaScript is > slow when polling the UI. setInterval is not polling the UI it call the flipcoin function, in my code. You guys complained i should not do the coinflips in a loop because there was no way to get the attention of DOM, canvas, UI while in loop. You suggested setInterval and setTimeout... That led me to beleive you suggested i should run coinflipping with 0 ms interval, or what did you actually mean Arno... > > > -- > Arno Welzel > https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2020-11-02 11:40 +0100 |
| Message-ID | <i0a615F53vaU1@mid.individual.net> |
| In reply to | #39102 |
Jonas Thörnvall: > Den måndag 2 november 2020 kl. 01:04:59 UTC+1 skrev Arno Welzel: [...] >> Yes - but you tried to use setInterval() with a delay of 0ms to keep a >> function running to poll to UI and then complained that JavaScript is >> slow when polling the UI. > > setInterval is not polling the UI it call the flipcoin function, in my code. > You guys complained i should not do the coinflips in a loop because there was no way to get the attention of DOM, canvas, UI while in loop. You still don't understand it. 1) When you create a loop which will constantly running this will block UI since JavaScript is not multithreaded and event handlers will not execute as long as your code is still busy with other things. 2) If you need something which runs all the time independent from any user input, either create a worker or use setTimeout()/setInterval() to "emulate" a background process by calling a function every x ms which executes only one thing at a time. What fits best for you depends on your application. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2020-11-11 00:21 -0800 |
| Message-ID | <1d05fe08-a358-47c9-90d0-f8892bedd621o@googlegroups.com> |
| In reply to | #39108 |
Den måndag 2 november 2020 kl. 11:40:47 UTC+1 skrev Arno Welzel: > Jonas Thörnvall: > > > Den måndag 2 november 2020 kl. 01:04:59 UTC+1 skrev Arno Welzel: > [...] > >> Yes - but you tried to use setInterval() with a delay of 0ms to keep a > >> function running to poll to UI and then complained that JavaScript is > >> slow when polling the UI. > > > > setInterval is not polling the UI it call the flipcoin function, in my code. > > You guys complained i should not do the coinflips in a loop because there was no way to get the attention of DOM, canvas, UI while in loop. > > You still don't understand it. > > 1) When you create a loop which will constantly running this will block > UI since JavaScript is not multithreaded and event handlers will not > execute as long as your code is still busy with other things. > > 2) If you need something which runs all the time independent from any > user input, either create a worker or use setTimeout()/setInterval() to > "emulate" a background process by calling a function every x ms which > executes only one thing at a time. > > What fits best for you depends on your application. > > > -- > Arno Welzel > https://arnowelzel.de Have not tested workers so can not tell, but calling function every xth millisecond is surely to slow for my application. I basicly was out after something similar to loop with a small penalty max 10 times slower. Rather 1.2 times slower, and i do not think that is going to happen, so i rather set a loop end, and do the calculations afterwards.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-11-11 09:13 -0800 |
| Message-ID | <9601faa2-cf5c-4642-805a-34bbb80561d0n@googlegroups.com> |
| In reply to | #39127 |
On Wednesday, November 11, 2020 at 2:21:42 AM UTC-6, jonas.t...@gmail.com wrote: > Have not tested workers so can not tell, but calling function every xth millisecond is surely to slow for my application. Only if you're doing too much in that function. The function calls themselves are not a problem. > I basicly was out after something similar to loop with a small penalty max 10 times slower. Rather 1.2 times slower, and i do not think that is going to happen, so i rather set a loop end, and do the calculations afterwards. We've already shown you how to do this in at least three different ways, and no doubt faster than what you have right now.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-11-01 16:19 -0800 |
| Message-ID | <5797d5b5-1a63-4e98-b287-0c006781109an@googlegroups.com> |
| In reply to | #39097 |
On Sunday, November 1, 2020 at 4:10:41 PM UTC-6, jonas.t...@gmail.com wrote:
> I do not think you understand the problem or i totally do it backward, tell me which....
>
> The timer doing no polls it doing function call using intervals to flip coins got it??????
Example:
<https://codepen.io/mlhaufe/pen/vYKjegN>
```html
<button id="btnStart">Start</button>
<button id="btnStop">Stop</button>
<button id="btnReset">Reset</button>
<hr>
<textarea id="txtOutput"></textarea>
```
```css
textarea {
width: 120px;
height: 200px;
}
```
```js
const qs = (sel, ctx) => (document || ctx).querySelector(sel);
const btnStart = qs("#btnStart"),
btnStop = qs("#btnStop"),
btnReset = qs("#btnReset"),
txtOutput = qs("#txtOutput"),
HT = "HT";
function randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
let animationId;
function start() {
// other setup work
animationId = requestAnimationFrame(step);
}
function step() {
animationId = requestAnimationFrame(step);
txtOutput.value += `${HT[randomInt(2)]}\r\n`;
}
function stop() {
// other cleanup work
cancelAnimationFrame(animationId);
}
function reset() {
txtOutput.value = "";
}
btnStart.addEventListener("click", start);
btnStop.addEventListener("click", stop);
btnReset.addEventListener("click", reset);
```
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web