Check this out. This little buddy rocks.
I sorta want to make a new FunctionUtil so that I can use it with impunity everwhere without having to include the other crap in here. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5730 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -59,6 +59,19 @@ public class Util
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a var-args function that will attempt to pass only the arguments accepted by the
|
||||
* passed-in function. Does not work if the passed-in function is varargs, and anyway
|
||||
* then you don't need adapting, do you?
|
||||
*/
|
||||
public static function adapt (fn :Function) :Function
|
||||
{
|
||||
return function (... args) :* {
|
||||
args.length = fn.length; // fit the args to the fn, filling in 'undefined' if growing
|
||||
return fn.apply(null, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified object is just a regular old associative hash.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user