Skip to content

Instantly share code, notes, and snippets.

@darimpulso
Created May 21, 2018 22:23
Show Gist options
  • Save darimpulso/2686e834c02a0af5af75bf9b678bfacb to your computer and use it in GitHub Desktop.
Save darimpulso/2686e834c02a0af5af75bf9b678bfacb to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var a = {
counter: 0,
b: {
c: {
d: function() {
for (var i=0;i<5;i++) {
setTimeout(function() {
console.log(i, ++this.counter);
}, 500);
}
}
}
}
};
a.b.c.d();
</script>
<script id="jsbin-source-javascript" type="text/javascript">var a = {
counter: 0,
b: {
c: {
d: function() {
for (var i=0;i<5;i++) {
setTimeout(function() {
console.log(i, ++this.counter);
}, 500);
}
}
}
}
};
a.b.c.d();
</script></body>
</html>
var a = {
counter: 0,
b: {
c: {
d: function() {
for (var i=0;i<5;i++) {
setTimeout(function() {
console.log(i, ++this.counter);
}, 500);
}
}
}
}
};
a.b.c.d();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment