Created
October 30, 2009 17:59
-
-
Save phiggins42/222589 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(d){ | |
d.compose = function(/* Function... */){ | |
// summary: Returns the composition of a list of functions. | |
// | |
// description: | |
// Returns the composition of a list of functions, where each | |
// function consumes the return value of the function that follows. | |
// | |
// additionally, if one of the functions returns an array, the values | |
// of that array are passed to the next function in the composition | |
// as positional arguments. | |
// | |
// example: | |
// | var greet = function(name){ return "Hi: " + name; }; | |
// | var exclaim = function(statement){ return statement + "!"; }; | |
// | var welcome = dojo.compose(greet, exclaim); | |
// | welcome("Pete"); | |
// | // Hi: Pete! | |
var list = d._toArray(arguments); | |
return function(){ // function | |
var a = arguments; | |
d.forEach(list, function(fn){ | |
a = fn.apply(this, d.isArrayLike(a) ? a : [a]); | |
}); | |
return a; | |
} | |
} | |
})(dojo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment