音が流れない場合、再生を一時停止してもう一度再生してみて下さい。
ツール 
画像
MBCode
30回再生
Creating Node Modules Part 8

Creating node modules. Understanding how node modules work is really important in creating node applications. What is a node module and what does it contain? We've seen before the node module usually contains reusable code, things Iike functions, classes, objects, and other data. Node module is meant to be reusable. That means you can include in other modules, and to do that you would just basically include it but usually require a command. To make that work though, you have to export the data, you need to be included in another module using the export or the module.exports command. Have a node here saying exports object is really just a reference to the module.exports object itself. It's hard to understand what that means until we see the actual code. Let's take a look at what the module may look like. Here an example, I have a module called module.js. Inside this file I have this module code, things like the names, scores, two variables contains some data. To export these two variables, I would attach them to either the exports object or the module.exports object, like you see here. Alternatively, you can use the object notation and attach them to the module exports, as you can see in the bottom here as well. You may wonder, what does this export and this module average come from? In the module in a node environment, it's all wrapped by this special function called a module wrapper. This wrapper function wraps all the data you see inside each file. That means because it's inside it's function, all the data are actually local to that module only. Any data that will not be visible to other modules until you export them out.

コメント