very good point i had not considered regarding the use with out new. 3. We want to export this as our default, so at the bottom of the file we write this: We could instead prepend export default onto the function and define it as an anonymous function, like this: Over in our main.js file, we import the default function using this line: Again, note the lack of curly braces. But with ES6, JavaScript has native modules. So far, our canvas shape drawing modules seem to be working OK. ES6 modules are stored in files. 'modules/square'). The following syntax form does that: This grabs all the exports available inside module.js, and makes them available as members of an object Module, effectively giving it its own namespace. In the dynamic-module-imports directory we've got another example based on our classes example. Even with some apparent losses like inheritance, there are still valid ways of implementing that benefits even with Modules. You can see an example of our shape drawing module rewritten with ES classes in our classes directory. How to draw a seven point star with one path in Adobe Illustrator. site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. Get the latest and greatest from MDN delivered straight to your inbox. This is much better than writing out the entire relative path each time, as it is shorter, and it makes the URL portable — the example will still work if you move it to a different location in the site hierarchy. This has some obvious performance advantages; let's read on and see how it works. A class defines all of the properties that characterize a certain set of objects (considering methods and fields in Java, or members in C++, to be properties). These examples demonstrate a simple set of modules that create a