I do defer execution of the factory until any dependencies of the module in question have been filled, so things executing in a different order should be a non-issue. The only things that will execute in an undefined order will be things that don't depend on each other anyway. Assuming the script doing the concatenating is smart enough to give anonymous modules ids matching the paths where they were found and so on, of course.
Maybe this is the real issue. I guess you could describe what I'm doing as eager loading:
- "Hey, a module has been defined. Let's load its dependencies."
- "Hey, this module has all its dependencies filled, lets execute its factory."
And the `require` way of doing things is more like lazy loading:
- "Hey, a module has been defined. Let's stick it somewhere in case some other module needs it."
- "Hey, a call to `require` happened! Let's start loading these dependencies."
Lazy loading may be the way to go, but adding another function to the global scope that is invoked in pretty much exactly the same way as `define` bugs me. At this point I'm thinking about having the `define` function return a Module object (the same type of object the inbuilt "module" dependency resolves to), and giving modules a `resolve` function or similar. So instead of this:
require(["foo"], function (foo) {
// do stuff
});
You would have this:
define(["foo"], function (foo) {
// do stuff
}).resolve();
It's ugly, but it makes sense (to me, anyway) and keeps the global scope clean.
I wonder if there should be some mention of lazy vs. eager loading in the spec, even if only to say the behavior is unspecified?