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
-
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.
👍