Doubt javascript function t (n, t, i, r)

11

I often see the source code of the pages and never understood that.

function dt(n,t,i,r)

What do these letters mean?

    
asked by anonymous 05.01.2017 / 09:06

3 answers

10

This was probably a code generated by a Javascript minifier.

When using minifiers, in addition to gaining in performance due to decreasing code size, you still have the advantage of having your code obfuscated (a technique used to decrease understanding of the logic of what was written).

An example is the code generated by the Yui Compressor.

Original code:

(function () {

    function StackOverflow(language) {

        var user, age;

        user = 'Wallace';
        age = 26;
    }

})()

Minimized code:

(function(){function a(d){var c,b;c="Wallace";b=26;}})();

Note that the name of the variables have been changed to just letters, as in your example.

    
05.01.2017 / 11:44
18

It is a javascript function with name dt and has 4 parameters n , t , i and r . It appears with these names because it is customary to minimize code to reduce file size, thereby saving traffic and eventually gaining some time to load the page.

Related

It is also possible that the function has been obfuscated and not minimized. The process of obfuscation gives possibility to keep the secret code being therefore of difficult interpretation by mortal beings, like us humans.

    
05.01.2017 / 09:13
7

I think that to complement the answer here is a basic explanation of how to create a function in javascript.

1) if you start using the word function followed by the name you want for the function.

2) Open parentheses, including the parameters that you want to use in the comma separated function. Close parentheses.

3) Opens keys to start the function block code. You enter the whole code of the function and at the end you can use the word return to return some value. If it does not return at the end of the function then it returns nothing and is called a return of type void.

Example 1: Function with return void:

<script>
function hello(nome)
{
    alert("Hello, " + nome + "! Welcome!");
}
</script>

Example of a call on a button:

<input type="button" onclick="hello('Alexandre')" value="Clique">

Example 2: Function with return.

<script>
// função com retorno
function soma(a,b)
{
    c = a + b;

    return c;
}

// Chamada da função, o retorno será guardado na variável minhasoma
minhasoma = soma(5,9);

alert(minhasoma);
</script>
    
05.01.2017 / 10:31