Created
May 7, 2012 23:30
-
-
Save LeZuse/2631417 to your computer and use it in GitHub Desktop.
JS Function.prototype.compose
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.compose = function(argFunction) { | |
var invokingFunction = this; | |
return function() { | |
return invokingFunction.call(this, argFunction.apply(this,arguments)); | |
} | |
} |
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 alertPower = alert.compose(Math.pow); | |
alertPower(9,8); //alert shows 43046721 | |
var roundedSqRoot = Math.round.compose(Math.sqrt); | |
roundedSqRoot(28); //5 | |
var queryString = String.prototype.substring.compose(String.prototype.indexOf).curry('?'); | |
queryString.call("http://www.wunderground.com?query=94101&weekday=Tuesday"); //?query=94101&weekday=Tuesday |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment