![]() ![]() const testFunction = () => from './mod1.js'Ĭonst testFunction = () => console.log('Im the main function')ĭocument.getElementById('isAlive').addEventListener('click', () => mod1Function())ĭocument.getElementById('isRolling').addEventListener('click', () => mod1Function2()) So create one by running npm init -y.įirst let's create a main.js file with a simple function in it. To implement modules, you need a Node app on your computer first. So let's see how CommonJS looks in actual code. The project was started by Mozilla engineer Kevin Dangoor in 2009.ĬommonJS is mainly used in server-side JS apps with Node, as browsers don't support the use of CommonJS.Īs a side comment, Node used to only support CommonJS to implement modules, but nowadays it also supports ESmodules which is a more modern approach. CommonJS modulesĬommonJS is a set of standards used to implement modules on JavaScript. It's the growth of the Javascript ecosystem that pushed for many of the changes that have come about. When analyzing the complexities of JavaScript and understanding how the language has evolved, I think it's important to have in mind that the language wasn't originally created to do what it does nowadays. Side comment: Did you know that Javascript was originally created in just 10 days of work? Of the many available, we're only going to take a look at CommonJS and ESmodules, which are the most recent and widely used ones. And so different options and libraries were developed to add this feature to JavaScript. Types of modulesĪs with almost everything in life, and especially in JavaScript, there are many ways for us to implement modules.Īs JavaScript was first created to be just a small scripting language for websites, a feature for big projects like modules wasn't supported at the beginning.īut as the language and the ecosystem grew, developers started to see the need for this feature. If this concept isn't clear enough now, don't worry. Instead of having all of our program's components in a single file, we can divide it into parts or modules, and make each of them responsible for a single feature/concern. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |