showing results for - "script id 3d 22worker1 22"
Chloé
25 Feb 2017
1<script id="worker1" type="javascript/worker">
2// This script won't be parsed by JS engines because its type is JavaScript/worker.
3// Simple code to calculate prime number and send it back to the parent page.
4      self.onmessage = function(e) {
5      self.postMessage("<h3>Worker: Started the calculation</h3><ul>");
6        var n = 1;
7        search: while (n < 500) {
8          n += 1;
9          for (var i = 2; i <= Math.sqrt(n); i += 1)
10            if (n % i == 0)
11              continue search;
12          // found a prime!
13          postMessage("<li>Worker: Found another prime: " + n + "</li>");
14        }
15        postMessage("</ul><h3>Worker: Done</h3>");
16      }
17</script>
similar questions
queries leading to this page
script id 3d 22worker1 22