0

I am trying to understand some of the source code behind Google AdSense. Google's code generator (here) says to put the following in the HEAD element:

<script type="text/javascript" charset="utf-8">
    ( 
        function(G,o,O,g,L,e) {
            G[g]=G[g] || function(){(G[g]['q']=G[g]['q'] || []).push(arguments)}, 
                    G[g]['t']=1*new Date; 
            L=o.createElement(O), e=o.getElementsByTagName(O)[0];
            L.async=1;
            L.src='//www.google.com/adsense/search/async-ads.js';
            e.parentNode.insertBefore(L,e) /* no semicolon...why? */
        } 
    )(window,document,'script','_googCsa'); /* argument list */
</script>

My knowledge of JS syntax is not very good, and I don't know answers to the following:

(1) A function inside a set of parentheses, and then what looks like an argument list,
(2) No semicolon after the last line in the curly braces...what's going on here?
(3) What is function(GoOgLe) actually doing? (I tried Googling "function(G,o,O,g,L,e)", but only got others' source code.)

Any help would be appreciated.

Community
  • 1
  • 1
user1505713
  • 615
  • 5
  • 20
  • 1
    (1) The function is being called with parameters `(window,document,'script','_googCsa')`. I.e. `G=window`, `o=document`, `O='script'`, `g='_googCsa'`. L and e are set in the function. (2) The semi-colon is not strictly necessary. Check JavaScript syntax documentation on this. (3) Hopefully you can answer this from (1) and (2). Good luck. – Matt Nov 26 '13 at 00:20
  • 1
    This question appears to be off-topic because it is a zero-effort post. If you want to learn Javascript, there are many free tutorials available. – Robin Green Nov 26 '13 at 20:46

0 Answers0