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

James Barrett
James Barrett
13,253 Points

A few questions on this workshop

Hello world!

I thoroughly enjoyed this course, very informative and has helped me understand functions (and closures!) a lot better.

I do have a few questions though:

  • Why can't we utilize the module.exports in Node.js for the front-end? It seems that syntactically it would make sense and would avoid a lot of confusion for users who are unaware of this design pattern.
  • Does anyone have any links to any existing GitHub repositories/files that use the modul pattern for the front-end? I'm intrigued as to how people implement this scenario in the real world.

Thanks, James.

2 Answers

Steven Parker
Steven Parker
231,269 Points

Front-end JavaScript engines don't run node.js.

So while node incorporates a JavaScript engine, an ordinary JavaScript engine as might be found in a browser won't quite do everything that node does.

The module.exports and require statement are unique features of node.

James Barrett
James Barrett
13,253 Points

Thanks for the answer Steven Parker ! I was looking further into importing and exporting and found this: https://www.youtube.com/watch?v=_3oSWwapPKQ

However it's not supported natively yet. Which is a shame as it seems like a really useful feature! But I suppose babel can help with that. My question is, are there any notable differences between loose augmentation and simply importing and exporting ?

Regards, James.

Steven Parker
Steven Parker
231,269 Points

It would probably be similar if you were just importing one term. But importing can potentially define several terms at once. But even that distinction would fade if the term in question were being used for dependency injection.