Strange global variables in, why?

    Hello, Habr!

    I could not decide how to arrange it for a long time - as a question in QA or as a post, as a result, the 4th paragraph of the rules for formatting the question alerted me - “it really contains a question, but not a reason for discussion.”, And I decided to do it by fasting.

    Until tonight, I thought that I was a little versed in JavaScript, and I even know some chips of client optimization:
    - for example, minimize and obfuscate scripts, glue them into one file and allow the browser to cache it;
    - I also strongly believe that it is impossible to clog a window with a large number of global objects, this can also affect performance and “quality” (this will be discussed in fact)

    I don’t remember what exactly prompted me to open the console in chrome development tools, being on (which I rarely go by the way), but there is

    no turning back ... At first I was surprised at the lack of jquery. The dollar symbol, of course, is busy, but not at all under jQuery, but under such a thing: An attempt to reach through jQuery also failed. Well, I thought, they probably, like yahoo, wrote their mega cool framework with blackjack and no jquery. But I decided to make sure that the window object does not have any strange property that jQuery was squeezed into (well, maybe it would be hiding in window.jqry). I wrote a window to the console, pressed enter, expanded the "tree" to see a list of object properties and ...

    function () { var curArgs =; return func.apply(obj, args.concat(curArgs)); }

    Of course, I could scrape this WADGE of global string variables, but at the moment you can do it yourself.

    It so happened that my professional activity is connected with social networks and the development of all kinds of social modules. And for optimization, when a social module is requested from our server (basically just a JavaScript file), an object is sewn into it with all the lines it needs (in the appropriate culture), urls, sometimes even styles. Then this file is cached by the browser \ Akamay \ by someone else and everyone is happy.

    The first thing I did was naturally open Facebook and check their window object for strange global variables. Alas, they probably managed to be removed from there)

    And the question is, is there any point in putting the lines directly in the window object? Maybe this is some kind of secret optimization?

    Just to believe that the scripts for the main page of a multi-million dollar social network were written by first-year students who did not hear anything about closure, I can’t, though ...

    PS The purpose of this post is extremely informative, I did not want to offend anyone.
    PSS Maybe tomorrow I will regret that I did not get enough sleep wrote this post, but today I am eager to find out the truth.

    It is noteworthy that window.all is “all”, and window.All is “all”

    Also popular now: