Skip to content

Instantly share code, notes, and snippets.

@dlmanning
Created January 22, 2015 04:06
Show Gist options
  • Save dlmanning/1605555460449fc9fc7c to your computer and use it in GitHub Desktop.
Save dlmanning/1605555460449fc9fc7c to your computer and use it in GitHub Desktop.
The mysterious case of the vanishing outer closure
zip();
zap();
zoom();
function zip () {
var a = 1;
(function () {
// v8 will remove the outer closure
debugger;
})();
}
function zap () {
var a = 1;
(function () {
eval('console.log("Hi mom!")'); // disable v8 optimizations
debugger;
})()
}
function zoom () {
var a = 1;
(function () {
// using a keeps the outer closure
var b = a + 1;
debugger;
})()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment