shenkwen shenkwen - 27 days ago 8
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', 'https://www.google-analytics.com/analytics.js', '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
a
and
m
as arguments? I see no difference in doing
var a
and
var m
in the function body.

Answer

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