Skip to content

Instantly share code, notes, and snippets.

@getify
Created June 30, 2018 04:03
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 getify/02734c16285032d527b3c5b1a38eca3b to your computer and use it in GitHub Desktop.
Save getify/02734c16285032d527b3c5b1a38eca3b to your computer and use it in GitHub Desktop.
illustrating a use-case for willfully violating "TDZ" for stylistic reasons
// 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];
}
// 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