Created
June 25, 2013 21:59
-
-
Save btford/5862848 to your computer and use it in GitHub Desktop.
this is why higher order programming was invented
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
var friendlify = function (fn, log) { | |
var patsOnTheBack = [ | |
'you are great', | |
'you\'re the best', | |
'wow you\'re awesome' | |
]; | |
log = log || console.log; | |
return function () { | |
var args = arguments; | |
log(patsOnTheBack[Math.floor(patsOnTheBack.length * Math.random())] + '!'); | |
return fn.apply(this, args); | |
}; | |
}; | |
// usage: | |
/* | |
var three = friendlify(function () { return 3; }); | |
three(); | |
// log: you are great! | |
// returns: 3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
💩 👍