Skip to content

Instantly share code, notes, and snippets.

@danielchikaka
Forked from LeZuse/function.js
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielchikaka/0674e24c3be4f5d01b8e to your computer and use it in GitHub Desktop.
Save danielchikaka/0674e24c3be4f5d01b8e to your computer and use it in GitHub Desktop.
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