I'm creating a Javascript project using the latest RequireJS. I'm defining a chessWorker module like so:
var worker;
define("chessWorker", ["jquery", "messageListener"], function($, listener) {
    if (worker) {
        return worker;
    } else {
        $.ajax({
            url: "...",
            success: function(data) {
                worker = new Worker(window.URL.createObjectURL(new window.Blob([data])));
                worker.onmessage = listener
                worker.error = function(e) {
                    ...
                };
                return worker;
            }
        });
    }
});
Is this bad practice? If so, how should I define this otherwise? Are there any standards concerning singletons on how they should be defined?
 
    