If there is someone who can help me understand this one, then I will be impressed. It's from # 28.
Here is a function for looping, and, if you look at the tutorial, it seems that it produces 6 pass below 3 times.
Please explain to you what is happening in this program, as explained in plain language in as much detail as possible:
-
fn call (array, array [i], i) function, and how do they all work, before the function array, then the array [i], And then I? What is happening when everything is happening?
-
In addition, in the function, I understand that
i ++ goes up every time that it goes through the array length, but increasing its value What doesnum ++ trigger for, and how tovalue == num ++in < Code> Function (value, i) , what is
value ? Is the value optional 0,1,2 of the loop array? If so, then those loop array numbers are used as a parameter in thefunction (value, i)? Code> What is the attempt to show it? how?.Code:
function loop (array, FN) {for (var i = 0; i & lt; array length; i ++) fn.call (array, array [i], i); } Var num = 0; Loop ([0, 1, 2], function (value, i) {emphasis (value == num ++, "make sure the contents are as good as possible"); (This presentation means " The reference should be an absolute array. ");});PASS Ensure that we expect this as the content.
The PASS reference should be a whole array.
Ensure that as soon as material is expected. The pass reference should be a whole array.
Ensure that as soon as material is expected. The pass reference should be a whole array.function is an anonymous function that works without a name < The complete second argument of the code> loopis the function (value, i) {Enter the value (value == num ++, "make sure the contents are expected as we Expect. "); Emphasis (this example is, "References should be a whole array."); }which is a complete anonymous task that takes three arguments:
this (for which the object is a method), the current value, and the loop counter .loop runs over the array again, and usesfn.call to call an anonymous function, it gives three arguments Done; Here, the array object should be clear, becausecall does not know which reference should be applied to the context in which context it is being applied (which is whatthis To call) in the call).Anonymized function, as is brought by
loop , is received in the form ofthis . The secondASSERT verifies this also expects that the value of the array is[0, 1, 2] and on each call thenum Enlarges and verifies it by comparing it with aligned array element.Therefore, after the execution series:
-
num is declared and is initialized on 0.- The
loop ([0, 1, 2], the function ...) is applied.loop invokesfn , with anonymous function, array (asthis ), its first element, andi which indicates the element offset (i is actually never used.)- Unknown function
ASSERT Comparing it withandnum later on.- The unknown function is
ASSERT that itsit aarray .loop invokesfn as in # 3, but from the second array element.- Anonymize function again sends its
ASSERT , this time it compares the second array element aligned, which would be 1 againstnum Hopefully (which is post-step 4 increments, 1).loop invokesfn before the third array element.- Anonymize function redoes its
ASSERT s, against the currentnum , the expected array compares the element 2, whose value is 2.
- The
Comments
Post a Comment