Skip to content

Instantly share code, notes, and snippets.

@hbt
Created August 11, 2017 15:43
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 hbt/3e71146454a2d6388338af1d76394a13 to your computer and use it in GitHub Desktop.
Save hbt/3e71146454a2d6388338af1d76394a13 to your computer and use it in GitHub Desktop.
function main() {
{
let bb = doSomething1()
let mm = doSomething2(bb, 'ww')
}
function doSomething2(var1, var2) {
console.log('nnw')
}
function doSomething1() {
console.log('hh')
}
}
main()
@hbt
Copy link
Author

hbt commented Aug 11, 2017

https://gist.github.com/hbt/3e71146454a2d6388338af1d76394a13#file-test-js-L5
This part is defined first when you're thinking of what function should do

https://gist.github.com/hbt/3e71146454a2d6388338af1d76394a13#file-test-js-L6
Use let inside a block to prevent variables from leaking out and being used accidentally in functions

https://gist.github.com/hbt/3e71146454a2d6388338af1d76394a13#file-test-js-L10
Inline functions are defined below and abstract a specific code block away but remain in the function to prevent unnecessary pollution and one-time use

https://gist.github.com/hbt/3e71146454a2d6388338af1d76394a13#file-test-js-L14
If a function needs to be reused, it can easily be extracted and refactored using IDE tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment