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 30958da + 5f3bc27 commit 16f9e21Copy full SHA for 16f9e21
doc/en/function/closures.md
@@ -96,6 +96,17 @@ above.
96
})(i), 1000)
97
}
98
99
+The other popular way to acheive this is to add an additional argument to
100
+the setTimeout function, which passes these arguments to the callback.
101
+
102
+ for(var i = 0; i < 10; i++) {
103
+ setTimeout(function(e) {
104
+ console.log(e);
105
+ }, 1000, i);
106
+ }
107
108
+Some legacy JS environments (Internet Explorer 9 & below) do not support this.
109
110
There's yet another way to accomplish this by using `.bind`, which can bind
111
a `this` context and arguments to function. It behaves identically to the code
112
above
0 commit comments