Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How does it work? - Q&A

How does it work?

0 like 0 dislike
There is a script in JS, I can someone explain how this works?

var scripta = ['slice', 'join', ..., 'split', 'map', 'charCodeAt', 'toString' ]; // left part for clarity (function(c, d) { var e = function(f) { while (f--) { c['push'](c['shift']()); } }; e(++d); }(scripta, 0xb9));
asked by | 10 views

1 Answer

0 like 0 dislike
The array of any of strings that are names of methods of some objects in JavaScript. But in the above code snippet is irrelevant since they are not executed.

Declares an anonymous function that is immediately invoked. It parameters are passed this array and number of 185recorded in 16 we used the hexadecimal system 0xB9.

Inside of a function declares another function e(f), pending an integer parameter f.

The while loop runs while this is the f-number reaches zero, decreasing by 1 on each iteration.

Inside the loop it calls a method of the array push()which will insert in the end of the array value. The properties and methods of an object can be accessed through the point of myArray.push() and square brackets by passing a string with the name of the property or method: myArray['push']()

Is inserted into the array the value taken out of it from the beginning. It is picked out of the array method shift() is written as a string in square brackets.

Calls the function e() with the number 185, is increased by 1, i.e., 186. In the loop this number is reduced first by 1, and then evaluated to see if it is equal to zero. If you haven't been, it runs the loop body. So the body of loop will be executed times 185: 185, 184, 183, 2 ... and 1.

The whole structure will move the contents of the array for some number of positions, depending on its length.
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


13.3k users

24,788 questions
46,220 answers
13,321 users