Why is the “this” an empty object in NodeJS?
Where does the “module.exports” belongs to?
I thought that "module.exports..." could be written as "this.module.exports..." but it won’t work.
Thank you
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.
If you are in an actual module:
moduleis a reference to the current moduleexportsis a reference to the exported data. It gets cached away by NodeJS and delivered to other modules thatrequireitthisis an alternate reference to theexportsobjectmodule.exportsis an alternate reference to theexportsobjectthis.moduleisundefinedthisis empty because as noted above it is a reference to the same object asexports, which is to be populated by the developer.If
this.modulewas a reference tomodule, then sincethisis a reference toexports, it would export themoduleitself along with the other exported items. I doubt this would be desired.If you are in the REPL, then
this.moduleis defined.