angular-bind-html-compile
angular-bind-html-compile copied to clipboard
Remove window reference
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.
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?
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 [email protected] 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 https://github.com/incuna/angular-bind-html-compile/issues/34#issuecomment-372935296, 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.