After experimenting with creating my own Javascript library, I am contemplating the best approach.
I recently discovered a convention for implementing private functions within a class by prefixing them with an underscore _
, yet they are still accessible. The code example looks like this:
export default class Test {
constructor() {
this._privateFunction();
}
_privateFunction() {
...
}
}
Instead of following this convention, I am considering placing functions outside the exported class. What are your thoughts on this possible solution?
export default class Test {
constructor() {
privateFunction();
}
}
function privateFunction() {
...
}
In my research, I have not found a way to access functions declared outside of the exported class, making it appear as a feasible alternative.
Do you think this is a good idea or could it potentially create issues with browser parsing?