Home > Article > Web Front-end > In-depth understanding of the concepts and usage of commonJS
The content of this article is to share with you an in-depth understanding of the concept and usage of commonJS. It has a certain reference value. Friends in need can refer to it
var moduleA = (function () { var aFlag = false; function keepMoving () { } b = 1; // 只暴露keepMoving 方法 return { keepMoving: keepMoving }; })()
var aFlag = false; function keepMoving () { } b = 1; module.exports = {//使用 module.exports 暴露接口 keepMoving: keepMoving };
//使用require加载模块A; var moduleA = require('./a.js'); function methodD() {//调用模块a里面的方法 moduleA.keepMoving(); } //暴露模块D的接口 module.exports = { methodD: methodD };
Related recommendations:
First introduction to commonjs
Brief understanding of CommonJS specifications
##javascript modularization of CommonJS, AMD, CMD, UMD, ES6
The above is the detailed content of In-depth understanding of the concepts and usage of commonJS. For more information, please follow other related articles on the PHP Chinese website!