-
-
Save getify/1abb4e0710a3eb56b04e9fbc9944b50d to your computer and use it in GitHub Desktop.
trying to figure out how closure works over params and body-vars
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
function foo(x,y = function(){ return x; }) { | |
console.log( "a:", x ); | |
var x = 1; | |
console.log( "b:", y() ); | |
} | |
foo(2); |
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
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); |
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
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