Skip to content

Commit 7e5c101

Browse files
committed
Merge pull request BonsaiDen#180 from naomik/patch-1
Add a `.bind` solution for setTimeout examples
2 parents 37b7cb9 + 6662d9c commit 7e5c101

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

doc/en/function/closures.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,10 @@ above.
9696
})(i), 1000)
9797
}
9898

99+
There's yet another way to accomplish this by using `.bind`, which can bind
100+
a `this` context and arguments to function. It behaves identially to the code
101+
above
102+
103+
for(var i = 0; i < 10; i++) {
104+
setTimeout(console.log.bind(console, i), 1000);
105+
}

0 commit comments

Comments
 (0)