Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,165 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
216,165 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.