We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 985da57 + 9b974a1 commit e57bd1fCopy full SHA for e57bd1f
js/setTimeout-inside-loop.js
@@ -81,17 +81,22 @@ for(var i=0;i<5;i++){
81
}
82
//use call/bind method(2)
83
for(var i=0;i<5;i++){
84
+//use bind/call to achieve this function, method(1)
85
+for(var i=0;i<10;i++){
86
+ setTimeout(console.log.bind(null,i),1000);
87
+}
88
+//use bind/call to achieve this function, method(2)
89
90
setTimeout(function(index){
91
console.log(index);
92
}.bind(null,i),1000);
93
94
//use call/bind method(3)
95
+//use bind/call to achieve this function, method(3)
96
for(var i=0;i<10;i++){
97
98
return function(){
99
100
101
}.call(null,i),1000);
102
-
0 commit comments