-
Notifications
You must be signed in to change notification settings - Fork 37
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
Comments
It's quite standard practice to reference global variables with |
It isn't standard at all, just an often copied pattern. The window object
is a host object (I.e. it is not even part of the language). You can be
quite sure to reference the correct value within the confines of the
language.
…On Wed, Mar 14, 2018, 4:01 AM Marcin Wolniewicz ***@***.***> wrote:
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?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#34 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AArScR8dFPd6vpXoOQr6GVObU_4Xyxl6ks5teM5fgaJpZM4SpiIs>
.
|
Still, I don't understand what is wrong with this pattern and why would you like it to be changed? |
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. |
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.
The text was updated successfully, but these errors were encountered: