Created
January 17, 2015 23:26
-
-
Save vladima/ac211a55df453297c3f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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