Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Last active October 11, 2015 10:07
Show Gist options
  • Save greggnakamura/3842386 to your computer and use it in GitHub Desktop.
Save greggnakamura/3842386 to your computer and use it in GitHub Desktop.
Javascript: functions
// Define a function within itself
var myfunction = function fun(number) {
myfunction = function( number ) {
return ++number;
};
return number * 2;
};
alert(myfunction(10)); // 20
alert(myfunction(10)); // 11
// Make a function to something expensive once, then cache for everyone else
var myfunction = function fun(number) {
// do object setup
var local = {};
myfunction = function() { return local;};
return local;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment