2👍
The cost of any API that is made public (which is what this does), is that you can no longer change or remove it, because someone, somewhere, may be using it, and you would break their code.
As an extreme example just look at how long it took to remove sun.misc.Unsafe
from Java, and how much code was broken by that removal even though the documentation explicitly stated that you are not allowed to use it. (In fact, sun.misc.Unsafe
is actually still there, so the removal actually failed because so much code uses it, even though it is explicitly forbidden to do so.)
If you export an API, you are making a promise to the users of that API. Only export APIs for which you are prepared to make and uphold that promise.
1👍
Besides @Jorg W Mittag’s great answer, if you’re thinking about performance, I don’t think it has any noticeable impact.
Your module will still get parsed by JS runtime even if you mark something as exported or not.
Probably your memory footprint is gonna be the same, as the module will keep references to internal methods anyway. I’m not sure if you’ll get a smaller memory footprint if you have internal methods that are not referenced from within the module, as they could be safely removed.