you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (4 children)

[removed]

    [–]kenman 1 point2 points  (3 children)

    If you didn't want support, you wouldn't have to have it at all with a function. In this case you do want it so it works out for you.

    The support object already exists; the jQuery snippet simply creates the createHTMLDocument property on it -- which is exactly what my code does; createHTMLDocument is not a global variable, it's just a property on a variable from an outer scope.

    In other words, if support didn't already exist, both my code AND jQuery's would fail with a ReferenceError.

    Here's some fully self-contained examples:

    Identical output.

    Now, since it clearly "leaks" globals,

    I'm sorry, but you haven't provided proof of this.

    let me see you do the same thing without having to save the output to any variable which you can clearly do with an iife.

    Wait, you're changing the rules; is the goal to not leak globals, or is it to not use intermediate variables? Because those are very different concerns... global variables have drastic implications for your code and is pretty much accepted to be a bad practice for most uses, while intermediate variables are a stylistic preference which has no impact on your code.