Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <span onclick="test(1)">test1</span><br/>
  <span onclick="test(2)">test2</span><br/>
  <span onclick="test(3)">test3</span><br/>
  <span onclick="test(4)">test4</span><br/>
  <span onclick="test(5)">test5</span><br/>
  <span onclick="test(6)">test6</span><br/>
  <span onclick="test(7)">test7</span><br/>
  <span onclick="test(8)">test8</span>
  
</body>
</html>
 
// for(var i = 0; i < 5; i++) {
//     setTimeout(function() { alert(i); }, 500);
// }
// var self = this;
// function fun() {
//   alert(self);
// }
// setTimeout(fun, 1000);
function test(i)
{
  var self = this;
  this.name = i;
  setTimeout( function()
  {
    alert( self.name );
  }, 5000 );       
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers