Skip to content

Commit 6662d9c

Browse files
author
Naomi
committed
Add a .bind solution for setTimeout examples
1 parent a8259ce commit 6662d9c

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)