Skip to content

Instantly share code, notes, and snippets.

@joshuajhun
Forked from rrgayhart/require.markdown
Created February 9, 2016 23:34
Show Gist options
  • Save joshuajhun/2dcb5b570e6ebf99cb8b to your computer and use it in GitHub Desktop.
Save joshuajhun/2dcb5b570e6ebf99cb8b to your computer and use it in GitHub Desktop.
The Concept of Require

When you start working with WebPack for GameTime, you'll notice that you can't just define a variable in one file and find it in another as easily as you can in Rails.

Read Node.js, Require and Exports and Organize Your Code with RequireJS

Fork this gist and answer the following questions:

  • In the context of Node, what is a module?
  • The code examples from the second blog post look very different from the first. Why?
@joshuajhun
Copy link
Author

  • In the context of Node a module is actually what is exported from the file. You have to explicitly export the value or export the Loaded file and require it in the other file or function you want to utilize. In comparison to the other blog you have a lot more control/restriction as to whats being passed through to the other modules. You don't have access to variables defined in other files unless they are exported. From what I got from this article I understand that it is actually the value of the variable that is actually exported
  • Because it is a different JS library? The way it required modules was through an array passed in through a define function that passed through another function (JavaScript-inception?). Seems kinda silly if you ask me. What I do like is that I then have access to those functions and and variables that are in the module.

@rrgayhart
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment