), we cannot pass parameters to the fn function handle, but we can bind the required parameters to the fn through the closure method.
for(var i=0,delay=1000; i
In this way, all the printed values are
i:5 delay:6000i:5 delay:6000i:5 delay:6000i:5 delay:6000i:5 delay:6000
Using the closure method, you can easily bind the parameters to be passed in:
for(var i=0, delay=1000; i
Output:
i:0 delay:1000i:1 delay:2000i:2 delay:3000i:3 delay:4000i:4 delay:500
pass parameters to the fn function handle, but we can bind the required parameters to the fn through the closure method.Copy codeThe Code is as follows:For (var I = 0, delay = 1000; I SetTimeout (function (){Console. log ('I:' + I + "delay:" + delay );}, Delay );} In this way, all the printed values areI: 5 delay: 6000I: 5 delay: 6000I: 5 delay: 6000I: 5 delay: 6000I: 5 delay: 6000Using the closure method, you can easily bind the parameters to be passed in:Copy codeThe Code is as follows:For (v
be operated directly anywhere else in the program. Only two counter operations can be performed.
In setTimeout (fn, delay), we cannot pass parameters to the fn function handle, but we can bind the required parameters to the fn through the closure method.
for(var i=0,delay=1000; i
In this way, all the printed values are
i:5 delay:6000i:5 delay:6000i:5 delay:6000i:5 delay:6000i:5 delay:6000
Using the closure method, you can easily bind the parameters to be passed in:
for(var i=0, delay=1000; i
use this method, plus this picture of the relevant words as long as the relationship can be added, can also be fabricated, [downstairs do not throw shoes] what is out of nothing, hehe, for example, ah, you picture is just a dog baby you can in the alt write a photo of the girl's girlfriend [of course you can't find a dog baby girl Friend photo of the case] hehe ...
Other pictures you can do it this way
Third: For too popular pictures, generally do not recommend everyone to do,
I made some very
.
12345
For ( VaR I = 0 , Delay= 1000 ; I 5 ; I ++, Delay + = 1000 ) { SetTimeout ( Function ( ) { Console. Log ( 'I :' + I + "Delay :" + Delay ) ; } , Delay ) ; }
In this way, all the printed values are
I:5Delay:6000I:5Delay:6000I:5Delay:6000I:5Delay:6000I:5Delay:6000
Using the closure method, you can easily bind the parameters to be passed in:
1234567
For ( VaR I = 0 , Delay = 1000 ; I 5 ; I ++, Delay + = 1000 ) {
directly manipulated anywhere else in the program, only through the two operations of the counter.At SetTimeout (FN, delay), we cannot pass arguments to the function handle of FN, but we can bind the required parameters to the FN by means of a closure method.for (var i=0,delay=1000; iIn this way, the printed values areI:5 delay:6000i:5 delay:6000i:5 delay:6000i:5 delay:6000i:5 delay:6000Instead of using closures, you can easily bind the parameters you want to pass in:For (var i=0, delay=1000; i
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.