CommonJs module pattern helps to add references to various js libraries as opposed to adding script tags in individual html pages thereby prevents all the UI pages from being getting polluted.The CommonJs module pattern only allowed one module per file - it there by eliminates circular dependencies and helps in finding out the properties regarding the current module.
// ourpackage is a dependency needed in the project
var lib = require('ourpackage');
// perform some action
lib.log('it is only a test');
// export Print to other modules
exports.Print = Print;
Asked In: Many Interviews |