-
-
Save getify/02734c16285032d527b3c5b1a38eca3b to your computer and use it in GitHub Desktop.
illustrating a use-case for willfully violating "TDZ" for stylistic reasons
This file contains 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
// my-common-js-module.js | |
const prefix = "ABC_"; | |
// NOTE: what's good here is that I'm using a `const`, but what's bad is, it's not | |
// located down below where my other "private" implementation details are. | |
// my public API for my module | |
module.exports = { | |
[`${prefix}1`]: 42, | |
[`${prefix}2`]: 100, | |
foo, | |
bar | |
}; | |
// all my private implementation details for my module | |
// ****************************** | |
var privStuff = [1,5,4]; | |
function foo() { | |
return privStuff[1]; | |
} | |
function bar() { | |
return privStuff[2]; | |
} | |
This file contains 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
// my-common-js-module.js | |
prefix = "ABC_"; | |
// NOTE: this is "better", IMO, in that it's initialized up here where it's needed, | |
// but it's still declared down below, alongside other private implementation details | |
// my public API for my module | |
module.exports = { | |
[`${prefix}1`]: 42, | |
[`${prefix}2`]: 100, | |
foo, | |
bar | |
}; | |
// all my private implementation details for my module | |
// ****************************** | |
var prefix; | |
var privStuff = [1,5,4]; | |
function foo() { | |
return privStuff[1]; | |
} | |
function bar() { | |
return privStuff[2]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment