I wrote a module to contain some of the less interesting bits of a large Javascript codebase I am working on, call it boring.js.
It is imported from a main module that does most of the more interesting work, call it main.js.
There is a class in boring.js called Log, which is exported to main.js and instantiated to a variable log. Calling the function log.save(newLogMsg) saves newLogMsg to file.
log.save(newLogMsg) works fine when called from main.js
When I try to call log.save(newLogMsg) from inside a function that resides in boring.js, I get the error:
ReferenceError: log is not defined
Which is confusing to me, because let log = new Log is initialized in the main module before I call the function in question (from main.js) that resides inside the imported module.
Side Question: Why can I call console.log(newLogMsg) from any module that I choose? How could I go about implementing a similar functionality for my Log class?