Skip to content

Instantly share code, notes, and snippets.

@vladima
Created January 17, 2015 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladima/ac211a55df453297c3f4 to your computer and use it in GitHub Desktop.
Save vladima/ac211a55df453297c3f4 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Test</title>
<script type="text/javascript">
"use strict"
function BigObject(x) {
this.x = new Array(x);
}
var callbacks;
function testVar() {
callbacks = createWithVar();
}
function testLet() {
callbacks = createWithLet();
}
function createWithVar() {
var bigObject = new BigObject(100000);
var result = [];
for (var x = 0; x < 1; ++x) {
(function(_x) {
var value = bigObject.x.length;
result.push(function() { return _x + value; });
})(x);
}
return result;
}
function createWithLet() {
var bigObject = new BigObject(100000);
var result = [];
for (let x = 0; x < 1; ++x) {
var value = bigObject.x.length;
result.push(function() { return x + value; });
}
return result;
}
</script>
<body>
<button onclick="testVar()">test var</button>
<button onclick="testLet()">test let</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment