Skip to content

Instantly share code, notes, and snippets.

@amiel
Created January 28, 2010 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiel/288533 to your computer and use it in GitHub Desktop.
Save amiel/288533 to your computer and use it in GitHub Desktop.
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