Paste: javascript

Author: slava
Mode: html
Date: Thu, 25 Aug 2011 00:06:24
Plain Text |
<script>
var g = {};
{
  var x = 10;
  var f = function() {
    alert(x);
  }
  g[0] = f;
}
var x = 20;
g[0]();
</script>

Annotation: how to do it

Author: Erich Ocean
Mode: html
Date: Thu, 25 Aug 2011 00:09:10
Plain Text |
<script>
var g = {};
(function() {
  var x = 10;
  var f = function() {
    alert(x);
  }
  g[0] = f;
}{();
var x = 20;
g[0]();
</script>

Annotation: how to do it

Author: Erich Ocean
Mode: html
Date: Thu, 25 Aug 2011 00:10:17
Plain Text |
<script>
var g = {};
(function() {
  var x = 10;
  var f = function() {
    alert(x);
  }
  g[0] = f;
})();
var x = 20;
g[0]();
</script>

Annotation: more confusion

Author: slava
Mode: html
Date: Thu, 25 Aug 2011 00:26:12
Plain Text |
This works:

<script>
f = function() {
	alert("x");
}
f();
f = function() {
	alert("y");
}
f();
</script>

This does not:

<script>
function f() {
	alert("x");
}
f();
function f() {
	alert("y");
}
f();
</script>

New Annotation

Summary:
Author:
Mode:
Body: