In both cases below, ID
is the exports object of the "id"
module.
require.ensure(["id"], function (require) {
var ID = require("id");
})
- In this example, the
"id"
module does not need to be loaded before executing this module. Because it uses therequire("id")
syntax, it is not simple to distinguish it from a dependency that must be preloaded.
require.async("id", function (ID) {
}, function (error) {
});
- does not accept multiple identifiers. The presumption is that it will be more common and usable for the loaded module to statically depend on anything you would be tempted to import in the same async call. If this presumption does not pan out (in my own use, it has), it is easy enough to extend this specification with spread/rest (variadic) arguments.
And I misread the UncommonJS/Modules ones from before. It had the exports passed to the "success" case. If you allow multiple IDs, then you get the AMD require:
That require does not have an error callback, but it has been brought up on the amd-implement list in some forms before, so I can see how that modification could make it into that require.
Anyway, just some compare/contrast notes.