Skip to content

Instantly share code, notes, and snippets.

@mkantor
Last active November 12, 2018 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkantor/869393fb4e6f37d237e4853949862246 to your computer and use it in GitHub Desktop.
Save mkantor/869393fb4e6f37d237e4853949862246 to your computer and use it in GitHub Desktop.
function bar(): void {
console.log('hello')
}
export class ClassWithClosedOverFunction {
constructor() {
bar()
}
}
/*
Advantages with this approach:
- Less line noise. There's no need to namespace `bar()` when calling it.
- `bar()` can be private for real on the JS side (just don't export it).
Disadvantages with this approach:
- ???
*/
export class ClassWithPrivateStaticMethod {
private static bar(): void {
console.log('hello')
}
constructor() {
ClassWithPrivateStaticMethod.bar()
}
}
/*
Advantages with this approach:
- Static functions are closer to the code that uses them and namespaced;
might aid readability?
Disadvantages with this approach:
- `bar()` is not actually private in the compiled JavaScript. Code can call
`ClassWithPrivateStaticMethod.bar()` from anywhere.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment