Skip to content

Instantly share code, notes, and snippets.

@rossedfort
Forked from rrgayhart/require.markdown
Last active February 16, 2016 22:12
Show Gist options
  • Save rossedfort/4b0e5d01dd84b6fef61b to your computer and use it in GitHub Desktop.
Save rossedfort/4b0e5d01dd84b6fef61b 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 in Node maps pretty much directly to a file. In Node, you can't require a file without exporting the contents within it. In ES6 with the ability to write classes, exporting a class gives you all of the methods defined within it. Every time you want to use the class and/or functions, you need to require that file.

  • The code examples from the second blog post look very different from the first. Why?

    The code samples in the second post look diffrerent because they are using RequireJS which is a javascript module loader. It uses a slightly different syntax. RequireJS looks at the dependencies of all the modules in your application, and will fetch and execute all of the modules in the proper order so that each module has exactly what it needs to run. define() takes an array of modules.

@rrgayhart
Copy link

👍

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