Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript The Module Pattern in JavaScript

Anthony c
Anthony c
20,907 Points

Is this out-of-date with ECMS6/2015?

or related to modules in ECMS6/2015?

1 Answer

Casey Ydenberg
Casey Ydenberg
15,622 Points

I would say it's up-to-date. Since no browsers actually support ES2015 yet, you have to use some kind of build tool to get the imported or required files into a single JavaScript file to serve. They still act as modules by "wrapping" the code from each file using a variation of this pattern. This is a good thing to know even if you are using Webpack/browserify/whatever (I can't keep up with all of it).

I'm excluding Node here where this pattern would probably not be a good idea/useful.

I'm also not sure whether, in the future, an import statement in the browser will trigger an HTTP request or if it's assumed that everyone will use some kind of transpiler by that point and the syntax is just a directive to it.