Created
February 24, 2010 20:50
-
-
Save seanmonstar/313836 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.prototype.lazy = function() { | |
var fn = this, | |
init = false; | |
return function() { | |
if(!init) { | |
init = true; | |
fn = fn.apply(this, arguments); | |
} | |
return fn.apply(this, arguments); | |
} | |
}; | |
var digit_name = function(n) { | |
var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; | |
return function(n) { | |
return names[n]; | |
}; | |
}.lazy(); | |
digit_name(3); //init, then return | |
digit_name(2); //return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment