I'm trying out making my own Javascript library and want to think it through.
I stumbled upon a convention to create private functions inside a class by prefixing it with underscore _
, but there's still access to them. It looks like this:
export default class Test {
constructor() {
this._privateFunction();
}
_privateFunction() {
...
}
}
I'm thinking about putting functions outside of exported class. Is this a good idea?
export default class Test {
constructor() {
privateFunction();
}
}
function privateFunction() {
...
}
I could not find a way to access the function, when declared outside of exported class, so it seems like a viable alternative.
Is it a good idea? Wouldn't it create problems with parsing in the browser?