Last active
October 11, 2015 10:07
-
-
Save greggnakamura/3842386 to your computer and use it in GitHub Desktop.
Javascript: functions
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
// 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