You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both conclude that using named access on the Window object should probably be avoided in preference to document.getElementById(). As I understand the reasoning, it is possible or even likely to get name collisions in the global window namespace which will result in unexpected behavior. For example, if you chose an element id which overlapped with an existing/reserved global/window property (IE: windows.closed or window.event), your router event would not be attached and would not fire.
I believe this is a bad practice, used without proper explanation in your code, and should not be included in a Free Code Camp article named at coding novices.
The text was updated successfully, but these errors were encountered:
I was reviewing your article on building a vanilla JS router on Free Code Camp's news, when I ran across this code:
I was confused, since I'd never seen this access of the window object. About 20 minutes of googling later led me to these two Stack Overflow responses:
https://stackoverflow.com/a/3434388/1420506
https://stackoverflow.com/a/11691401/1420506
Both conclude that using named access on the Window object should probably be avoided in preference to
document.getElementById()
. As I understand the reasoning, it is possible or even likely to get name collisions in the global window namespace which will result in unexpected behavior. For example, if you chose an element id which overlapped with an existing/reserved global/window property (IE:windows.closed
orwindow.event
), your router event would not be attached and would not fire.I believe this is a bad practice, used without proper explanation in your code, and should not be included in a Free Code Camp article named at coding novices.
The text was updated successfully, but these errors were encountered: