Last active
November 12, 2018 21:11
-
-
Save mkantor/869393fb4e6f37d237e4853949862246 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
- ??? | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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