Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Runaway pollution of global namespace #1

Closed
rjgotten opened this issue Nov 1, 2013 · 3 comments
Closed

Runaway pollution of global namespace #1

rjgotten opened this issue Nov 1, 2013 · 3 comments
Assignees

Comments

@rjgotten
Copy link

rjgotten commented Nov 1, 2013

The following variables are undefined and will be created on the global window object:

  • winWidth
  • winHeight
  • winBottom
  • winRight
  • elHeight
  • elWidth
  • elTop
  • elLeft
  • scrollLeft

You are declaring scrollTop correctly, atleast for now. However, the fact that it has a trailing comment that specifically mentions "probably not needed" does not bode well.

@silvestreh
Copy link
Owner

Hi! I usually comment my code a lot so I can understand what I was trying to do when I look at it weeks later. This is the first time I write a jQuery plugin and I'm still kind of new to Javascript, so I had to do a little research of "global namespace pollution" and (if I understood) you're right, these variables don't need to be global.

Now, what I don't completely get is why are they global variables when I declare them inside a function? Is it because I'm not using var to declare them?

Thanks!

@ghost ghost assigned silvestreh Nov 1, 2013
@silvestreh
Copy link
Owner

If you're in the global scope then there's no difference.

If you're in a function then "var" will create a local variable, "no var" will look up the scope chain until it finds the variable or hits the global scope (at which point it will create it)

Yup, that darn var that I forgot to use. Thank you, I'll push the changes in a minute :-)

@silvestreh
Copy link
Owner

Fixed. Thank you! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants