Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Created May 7, 2012 23:30
Show Gist options
  • Save LeZuse/2631417 to your computer and use it in GitHub Desktop.
Save LeZuse/2631417 to your computer and use it in GitHub Desktop.
JS Function.prototype.compose
Function.prototype.compose = function(argFunction) {
var invokingFunction = this;
return function() {
return invokingFunction.call(this, argFunction.apply(this,arguments));
}
}
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