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

Asked

Viewed 218 times

11

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

function dt(n,t,i,r)

What do those letters mean?

3 answers

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 the file size, thus saving traffic and eventually gaining some time in loading the page.

Related

It is also possible that the function has been obfuscated and not minimized. The process of obfuscation makes it possible to keep the code secret and is therefore difficult to interpret by mortal beings, such as us humans.

  • These are 4 arguments or 4 parameters, I always have this doubt of who is who in the functions...

  • @Magichat Depends on how you write the sentence. Arguments are received by the function. The function caller passes arguments to the function. But the function has parameters and not arguments. It is correct that I say that it takes 4 arguments but it is not correct to say that it has 4 arguments. You’d have to say she has 4 parameters. see the question and this also

  • Vlw man, I had already read these 2 and some others (sometimes), but only now things start to seem to make sense.

10


Probably, this was code generated by a Javascript minificador.

When using mini-directors, in addition to winning in performance because of decreasing the size of the codes, you still have the advantage of having your code overshadowed (technique used to lessen the understanding of the logic of what was written).

An example is the code generated by Yui Compressor.

Original code:

(function () {

    function StackOverflow(language) {

        var user, age;

        user = 'Wallace';
        age = 26;
    }

})()

Minified code:

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

Note that the name of the variables were exchanged for only letters, as in your example.

  • +1. I like the minification example. I really like examples because it’s easy to see things. Now I have one more question that perhaps you can answer by supplementing your answer. Why does this code have these external parentheses wrapped around the function and the two empty at the end? (Function(){...})()

  • 4

    @Antonioalexandre this is a "self-executable function". It is a function that is called at the same time it is declared. We use this to protect the scope and prevent variables from being "loose" in the global scope.

  • I was going to die without knowing it! I always found these parentheses bizarre around the function in some codes. Thank you so much for the explanation! If I could give +2 on the answer. D

7

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

1) starts using the word Function followed by the name you want for the function.

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

3) Opens keys to start function block code. You type all the code of the function and at the end you can use the word Return to return some value. If there is no Return at the end of the function then it returns nothing and is called void type return (empty).

Example 1: Function with void return:

<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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.