JavaScript modules
organized and re-usable code (the "set phrases")
Organizing JavaScript code into reusable modules allows for:
namespace cleanliness: variable names do not get reused and cause confusion
instead of calling doStuff, you would call moduleX.doStuff and ensure that moduleX is unique to the program
functional focus: have one piece of code do one thing and one thing well!
this also makes the code more portable and shareable
we don't even have to know how they work internally
we just care that they do what we want them to do
These ways require ES6 (i.e. use Babel if required) and assume that the imported module lives in the same folder as the importing module
Newer way of doing modules (used in React)
moduleToExport.js
moduleThatImports.js
Older way of doing modules
moduleToExport.js
moduleThatImports.js
Last updated