Created
January 28, 2010 07:43
-
-
Save amiel/288533 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
function complex_function() { | |
var local_variable = "foo"; // gets defined every time complex_function is run | |
var result; | |
var private_helper = function() { // this function gets declared every time complex_function is run | |
return local_variable; | |
}; | |
// ok, this is actually what this function does | |
result = private_helper(); | |
return result; | |
} | |
Ruby.puts(complex_function()); | |
var another_complex_function = (function() { | |
var local_variable = "bar"; // defined once | |
var private_helper = function() { // defined once | |
return local_variable; | |
}; | |
var do_stuff = function() { | |
var result; | |
result = private_helper(); | |
return result; | |
}; | |
return do_stuff; | |
})(); | |
Ruby.puts(another_complex_function()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment