internet explorer - Why is it bad to make elements global variables in Javascript? -


I have heard that it is not a good idea to make elements global in JavaScript, I do not understand why Can not handle this IE?

For example:

  div = getElementById ('topbars');  

I do not think this is an implementation issue, but a good bad behavior issue. Generally global * is bad behavior and should be avoided (global variable and so on) because you really do not really know how the scope of this project will develop and how your file will be included.

I am not a big JS quirky why can not I specifically tell you why JS events are bad, but you can see a look. In addition, try to Google to "best practice"

Edit: Global variables about Wikipedia, which may also apply to your problem:

[Global variables] are generally considered to be bad behaviors properly due to their non-specificity: A global variable can potentially be modified from anywhere (unless they remain in protected memory) and programs On any part of Maybe over a global variable therefore has an unlimited ability to create mutual dependence, and increased complexity of adding interdependence. See action at a distance, however, in some cases, global variables may be suitable for use. For example, they can be used to avoid continuous continuous-used variables in many functions.

via


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -