requireJS require 函数有一个没有定义的模块名称

requireJS require function has a module name without a definition

我正在尝试理解这段代码

    require(['mifosXComponents'], function (componentsInit) {
        componentsInit().then(function(){
            require(['test/testInitializer'], function (testMode) {
                if (!testMode) {
                    angular.bootstrap(document, ['MifosX_Application']);
                }
            });
        });
    });

密码在mifosX client code。我相信这是 mifosX 网络客户端软件的入口点。我真的对这里的 require 语法感到困惑。我看到的所有在线示例代码都像require(["a", "b"], function (a, b){});。也就是说,function()里面的参数列表都在它前面的依赖[]里面列出了。但是我上面粘贴的代码在 function() 中有 componentsInit。而且我在源代码树中找不到定义 componentsInit 的任何地方.....

我在这里尝试的是理解mifosX的代码逻辑流程。我是 Javascript 和 RequireJS 的新手。如果您知道这里发生了什么,请帮助我理解这一点。提前致谢!

这是您的代码,其中包含一些注释,可以阐明:

// in the first line you are requiring a module with id `mifosXComponents`
// which then is passed to the callback as `componentsInit`
require(['mifosXComponents'], function (componentsInit) {
    // seems that `componentsInit` is a function which returns a Promise object,
    // so your are passing a callback to it to execute it after its fulfilment 
    componentsInit().then(function(){
        // when the promise is fulfilled, you are requiring another module
        // with id `test/testInitializer` which is passed to callback as `testMode`
        require(['test/testInitializer'], function (testMode) {
            // next lines are pretty simple to understand :)
            if (!testMode) {
                angular.bootstrap(document, ['MifosX_Application']);
            }
        });
    });
});

关于 Promise 你可以在这里阅读:What does the function then() mean in JavaScript?