Skip to content

Instantly share code, notes, and snippets.

@adamki
Forked from rrgayhart/require.markdown
Last active February 9, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamki/5555ab7529a4b377aef4 to your computer and use it in GitHub Desktop.
Save adamki/5555ab7529a4b377aef4 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? A module is a the essential building block of Node. In node, a module maps directl to a file. The contents of said file are still private and node requires that any access to the files' contents be explicetely returned.

require is used to load a module.

  • The code examples from the second blog post look very different from the first. Why? The code is vastly different because the second post ( treehouse blog ) introduces the requireJS library. This allows the developer to use a define() function. In short, anything within the define() function is returned and can be exported to another file.

requireJS also allows you to specify what module dependencies will be needed. YOU can pass file name in the define() fundtion as function parameters.

lastly, requireJS gives us the require() function which is run immediately(it is NOT stored as a module). The benefit of this is so we can assign all module depencies in main.js and require said file fro our HTML file easily.

@rrgayhart
Copy link

Excellent!

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