Skip to content

Instantly share code, notes, and snippets.

@getify
Created September 8, 2016 22:37
Show Gist options
  • Save getify/1abb4e0710a3eb56b04e9fbc9944b50d to your computer and use it in GitHub Desktop.
Save getify/1abb4e0710a3eb56b04e9fbc9944b50d to your computer and use it in GitHub Desktop.
trying to figure out how closure works over params and body-vars
function foo(x,y = function(){ return x; }) {
console.log( "a:", x );
var x = 1;
console.log( "b:", y() );
}
foo(2);
function bar(x,y = function(){ console.log( "d:", x ); x = 1; }) {
var x;
console.log( "c:", x );
x = 2;
y();
console.log( "e:", x );
}
bar(3);
Chrome 52-
a:2, b:2, c:3, d:3, e:2
Firefox51-
a:2, b:1, c:3, d:2, e:1
Babel(6/SiteRepl)-
a:2, b:1, c:3, d:2, e:1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment