Tuesday, 13 November 2018

Confusion about Module.exports.

I'm having some trouble in the functionality of Module.exports and was hoping someone could give me some clarity. I've always been under the impression that exports returned a copy of it's object in the main file, so if i were to require() say a function from another file, it would work the exact same way as if i had wrote the function in the main file, is this not the case? In my case, i'm importing an algorithm function into my main file, however when i attempt to run the function on the data object that is defined in the main file i get a reference error. The program runs just fine when i write the imported function in the main file, but when imported it does not have access to objects that aren't passed to it as a param. The obvious answer is to pass the data object as a param, but i feel like this would cause a serious performance hit as it's several MBs of data and the function gets run 100s of times per second. Any incite would be appreciated.

Submitted November 14, 2018 at 07:45AM by captainXcannabis

No comments:

Post a Comment