I’ve been trying to get my head around node.js so I’ve been taking apart the chat demo they made here http://chat.nodejs.org/
I’m getting round to understanding it apart from this line var fu = exports;. Could anyone help me out?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
exportsis a special local variable in node.It’s basically a variable you can add properties to that will be exported when another module require’s your module.
So
var fu = exports;is saying alias exports tofu. This means you can add properties tofuand they will exported by default.So there are two similar patterns
or
The important thing of both cases is that
exports.xis set so that when you require MyModule you can userequire("MyModule").x