繁体   English   中英

RequireJS 与 CommonJS 模块

[英]RequireJS with CommonJS modules

使用 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 将被忽略? 或者是周围的其他方式?

是的,如果你返回一些东西 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();
   };
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM