Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of javascript parameters that are overwritten in the function?

Tags:

javascript

I have a code snippet to include in a project, and I'd like to know if there's a purpose to why it was written like this or if I should clean it up. Is there an optimization trick I don't know about?

Here's the (sanitized) code snippet. Notice a,b,c,d passed in and then assigned in the function.

(function (a, b, c, d) {
    a = '//url/to/js/file.js';
    b = document; c = 'script'; d = b.createElement(c); d.src = a; d.type = 'text/java' + c; d.async = true;
    a = b.getElementsByTagName(c)[0]; a.parentNode.insertBefore(d, a);
})();

I found this answer after writing this question up. Is that the only reason?

like image 931
Jamie Avatar asked Oct 22 '22 10:10

Jamie


1 Answers

That way you can make a local scoped variable without explicitly declaring it using var statement.

IIRC it's commonly used by code minifiers.

like image 121
Dogbert Avatar answered Nov 15 '22 05:11

Dogbert