Curry-1.0.1.js 715 字节
Newer Older
P
p4u 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/**
 * Curry - Function currying
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
 * Date: 10/4/2008
 *
 * @author Ariel Flesler
 * @version 1.0.1
 */

function curry( fn ){
	return function(){
		var args = curry.args(arguments),
			master = arguments.callee,
			self = this;

		return args.length >= fn.length ? fn.apply(self,args) :	function(){
			return master.apply( self, args.concat(curry.args(arguments)) );
		};
	};
};

curry.args = function( args ){
	return Array.prototype.slice.call(args);
};

Function.prototype.curry = function(){
	return curry(this);
};