Sign In Register

How can we help you today?

Start a new topic

is there a way to check if a module has already been loaded?

I use modules a lot and sometimes a module might be called when it was already previously called. This is bad since it reopens one and that's a waste of time. So is there a way to track if one has already been opened as to not repeat it?


Set a bogus variable in the module, then you can check if the variable exists. If it exists, the module was loaded.

You can do something like this:

in module Foo:


  

this.Foo = this.Foo || (function() {
    var self = {};

    self.bar = function() {
        // do stuff
    }

    return self
})();

  Than you can do anywhere in cloude code:

   

require("Foo");

Foo.bar();

   

Login to post a comment