Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Requirejs and Commonjs crossmodule standard boilerplate

View 01 moduleA (return value).js
1 2 3
(typeof define==="function"?define:function(f){var r=f(require,exports,module);module.exports=(r!==void 0?r:module.exports);})(function(require,exports,module){
return 27;
})
View 01 moduleA (return value).js
1 2 3
(typeof define==="function"?define:function(f){var r=f(require,exports,module);module.exports=(r!==void 0?r:module.exports);})(function(require,exports,module){
module.exports = 27;
})
View 01 moduleA (return value).js
1 2 3
define(['moduleA'], function(moduleA){
console.log(moduleA); // 27
})
View 01 moduleA (return value).js
1 2 3
define(function(require, exports, module){
console.log(require('moduleA')); // 27
})
Owner

Module we are making:

  • moduleA.js: returning the module;
  • moduleB.js: setting the module.exports variable;

Both way works the same. But remember to don't do both: you should not return a module and also set the module.exports variable;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.