Circular Dependencies in modules using requireJs

前端 未结 3 1065
执念已碎
执念已碎 2021-01-04 20:47

Reading the requireJs documentation,
in order to fix the Circular Dependencies, is suggested to use exports to create an empty object for the module that is

3条回答
  •  既然无缘
    2021-01-04 21:19

    You should be able to use the synchronous version of require() in your B module to access the "A" module:

    // B module
    define([
        'a',
        'exports'
    ], function (a, exports) {
        console.log('A:', a); // A, undefined (as I was expecting)
        exports.A = function () {
            return require('a');
        }
        ...
    });
    

提交回复
热议问题