incuna / angular-bind-html-compile

Directive that calls $compile on trusted HTML, allowing directives in an API response.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove window reference

david-mark opened this issue · comments

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?

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.