JSFiddle - React, Tailwind, and code Playground

by ubershmekel

HTML

<div id="result"></div>

JavaScript

var newWorker = function (funcObj) {
    // Build a worker from an anonymous function body
    var blobURL = URL.createObjectURL(new Blob(['(',

    funcObj.toString(),

        ')()'], {
        type: 'application/javascript'
    })),

        worker = new Worker(blobURL);

    // Won't be needing this anymore
    URL.revokeObjectURL(blobURL);

    return worker;
}

var w = newWorker(function () {
    var i = 0;

    function timedCount() {
        i = i + 1;
        postMessage(i);
        setTimeout(timedCount, 500);
    }

    timedCount();
});

w.onmessage = function (event) {
    document.getElementById("result").innerHTML = event.data;
};