Last active
December 11, 2015 07:18
-
-
Save ryasmi/4565135 to your computer and use it in GitHub Desktop.
This runs a recursive function and assigns the result of the recursions to a variable without leaking the function in global scope.
This file contains hidden or 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
var foo = (function me(x) { | |
if (x < 10) { | |
return me(x + 1); | |
} | |
else { | |
return x; | |
} | |
}(1)); | |
// In this case foo will be equal to 10. | |
// Calling me(1) will throw a reference error when called outside the function "me". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment