Is it a bad practice to use the requireJS module as a singleton?

No, I cannot think of a reason against using singletons with require.js.

Your module definition should export the singleton. The way you do it is fine, since it’s a singleton you might be also able to avoid the new. I use something like

define(function (require) {
    var singleton = function () {
        return {
            ...
        };
    };
    return singleton();
});

The first require to the module will load and export it. Some other module requiring your singleton will just reuse the already exported one.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)