Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove window reference #34

Open
david-mark opened this issue Mar 13, 2018 · 4 comments
Open

Remove window reference #34

david-mark opened this issue Mar 13, 2018 · 4 comments

Comments

@david-mark
Copy link

Found this thing in my current project and couldn't help but wonder why the window object was referenced. Just pass a reference to the global - angular - variable. Better yet, just reference it as it is a global. The window object shouldn't enter into it.

@wytrych
Copy link
Collaborator

wytrych commented Mar 14, 2018

It's quite standard practice to reference global variables with window when using code wrapped in IIFE. Unless of course you want to use it outside of a brower context, but that's not the case here. The reason is that when using window explicitly, we are sure we're referencing the global angular instead of some random variable that might have been declared before the IIFE. What do you find odd about it?

@david-mark
Copy link
Author

david-mark commented Apr 11, 2018 via email

@wytrych
Copy link
Collaborator

wytrych commented Apr 11, 2018

Still, I don't understand what is wrong with this pattern and why would you like it to be changed?

@david-mark
Copy link
Author

First of all, the reference to the - window - object is in the global scope. As there is only one object in the scope chain, which is the Global Object, there's no reason to reference - angular - this way. It's just a pointless (and odd) dot operation.

Second, in the global scope, the - this - object references the Global Object, so you could have used that instead of the - window - host object. There's never a reason to use a host object to reference a global variable; if there were, the language would clearly be broken.

As for wanting it changed, I really don't care. Just thought I'd point out some odd choices in the code. On an unrelated note, it's no longer used in my current project.

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

No branches or pull requests

2 participants