cli-cube-timer icon indicating copy to clipboard operation
cli-cube-timer copied to clipboard

Use "_" as prefix for all global variables and do not pass them around as function arguments

Open icyflame opened this issue 7 years ago • 4 comments

icyflame avatar Dec 19 '17 07:12 icyflame

do not pass them around as function arguments means we can't use global variables as arguments?

Saurabh3333 avatar Dec 19 '17 19:12 Saurabh3333

@Saurabh3333 Yes.

icyflame avatar Dec 20 '17 03:12 icyflame

Sir, what is the problem with passing the global variables as function arguments?

Saurabh3333 avatar Jan 06 '18 18:01 Saurabh3333

@Saurabh3333 it's not a good practice. Global variables are available everywhere in JavaScript, they needn't be passed around as function arguments. It also makes following the code harder for anyone who hasn't worked with JavaScript before. Questions like "If the variable is available everywhere, why is it being passed as a function argument? Is there some reason I am missing?"

It's messy, of course. I shouldn't have used global variables in the beginning, when I was designing this module. I ended up using them. So, I think the second best option, after completely refactoring index.js, is to embrace the fact that index.js has global variables!

icyflame avatar Jan 07 '18 14:01 icyflame