-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclosure_practice2.html
More file actions
47 lines (36 loc) · 822 Bytes
/
closure_practice2.html
File metadata and controls
47 lines (36 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<title>Closure Practice 2</title>
</head>
<body>
<script type="text/javascript">
const array = [1,2,3,4];
for(var i = 0; i <array.length; i++) {
(function(closureI) {
setTimeout(function(){
console.log("I am at index " + closureI)
}, 3000)
})(i);
}
// function doSetTimeout(i) {
// setTimeout(function(){
// console.log("I am at index " + i)
// },3000)
// }
// for (var i = 0; i < array.length; i++) {
// doSetTimeout(i);
// }
// array.forEach(function(element, index) {
// setTimeout(function(){
// console.log("I am at index " + index)
// }, 3000)
// })
// setTimeout(function(){
// for(var i = 0; i <array.length; i++) {
// console.log("I am at index " + i)
// }
// }, 3000)
</script>
</body>
</html>