shenkwen shenkwen - 1 year ago 54
Javascript Question

why makes anonymous function have more arguments in its statement then in the invocation

(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '', 'ga');

ga('create', 'UA-28239486-5', 'auto');
ga('send', 'pageview');

This is the Google Analytics script. In the anonymous function, there are 7 arguments, but when being invoked, there are only 5. Why then the code would make
as arguments? I see no difference in doing
var a
var m
in the function body.

Answer Source

When you are trying to make the file as small as possible, you look for ways to reduce the number of characters. Yes they can use var, but that also adds 5 more characters to the size of the code.

var a, m;
1234    5
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download