2015-06-10 116 views
-1

与CommonJS的模块使用RequireJS,我这样做的时候会发生什么:RequireJS与CommonJS的模块

define(function(require, exports, module) { 
    //Put traditional CommonJS module content here 

    var simpleCommonJSModule = require('simple-commonjs-module'); 

    module.exports = new String('foo'); 

    return { 
     //return empty object along with using module.exports 
    } 
}); 

如果我返回的东西,我假设module.exports将被忽略?或者是周围的其他方式?

回答

1

是的,如果你返回的东西module.exports将被忽略。

这是原始文档的一个片段。

define(function(require, exports, module) { 
     var a = require('a'), 
      b = require('b'); 

     //Return the module value 
     return function() {}; 
    } 
); 

如果你想使用exports CJS风格这就是你做

define(function(require, exports, module) { 
    exports.foo = function() { 
     return a.bar(); 
    }; 
}); 
+0

是啊,所以我想请问这是怎么AMD/RequireJS垫片CommonJS的模块,只需通过与定义功能包装他们,然后在出口报表之后返回一个值 –