Reputation: 919
Okay, so I've tired quite a few things. And I'm still boggled, and I know the answer is going to be something ridiculously simple, but I have to ask anyway.
I have a function:
Module.load = function(a) {
require("./modules/"+a+".js");
Module.loaded.push(a);
Log("Loaded Module: "+a);
};
And using Module.load('basic');
loads the basic file.
Now, I'm defining modules via an object:
Modules = { basic:1,queue:0,admin:1,notify:0 }
So I wrote this function:
for (x in Modules) { if (Modules[x] == 1) Module.load(x); };
But it's not working, and for the life of me, I can't figure out why.
Upvotes: 2
Views: 76
Reputation: 63442
The code works:
var Module = {}; Module.load = function(a) {
console.log("Loaded Module: "+a);
};
var Modules = { basic:1,queue:0,admin:1,notify:0 }
for (var x in Modules) { if (Modules[x] == 1) Module.load(x); };
Loaded Module: basic
Loaded Module: admin
Therefore the problem must be elsewhere. Make sure that:
Module.loaded
exists and is an arrayrequire
is defined as a function and doesn't crashLog
is defined as a function and doesn't crashUpvotes: 4