Contains a variety of utility functions.
public static function adapt(fn:Function, ... prepend):Function
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? An array of arguments to prepend to each call may also
be given.
Parameters
Returns
Example
// let's say you have this function
function printUser (user :User) :void
{
trace("UserId: " + user.id + ", name: " + user.name);
}
// and you want to print all your users. (Normally the forEach callback requires 3 params)
allUsersArray.forEach(Util.adapt(printUser))
// now let's say you have this function
function printUser (indent :String, user :User) :void
{
trace(indent + "UserId: " + user.id + ", name: " + user.name);
}
// and you want to print all your users with some spaces before each line:
allUsersArray.forEach(Util.adapt(printUser, " "))
public static function equals(obj1:Object, obj2:Object):Boolean
A nice utility method for testing equality in a better way.
If the objects are Equalable, then that will be tested. Arrays
and ByteArrays are also compared and are equal if they have
elements that are equals (deeply).
Parameters
Returns
public static function getDefault(props:Object, name:String, defaultValue:Object):Object
Returns a property of an object by name if the object contains the property, otherwise
returns a default value.
Parameters
| props:Object |
|
| name:String |
|
| defaultValue:Object |
Returns
public static function init(target:Object, initProps:Object, defaults:Object = null, maskProps:Object = null):void
Initialize the target object with values present in the initProps object and the defaults
object. Neither initProps nor defaults will be modified.
Parameters
| target:Object — any object or class instance.
|
|
| initProps:Object — a plain Object hash containing names and properties to set on the target
object.
|
|
| defaults:Object (default = null ) — a plain Object hash containing names and properties to set on the target
object, only if the same property name does not exist in initProps.
|
|
| maskProps:Object (default = null ) — a plain Object hash containing names of properties to omit setting
from the initProps object. This allows you to add custom properties to
initProps without having to modify the value from your callers.
|
Throws
| — if a property cannot be set on the target object.
|
public static function isPlainObject(obj:Object):Boolean
Returns true if the specified object is just a regular old associative hash.
Parameters
Returns
public static function isSimple(obj:Object):Boolean
Is the specified object 'simple': one of the basic built-in flash types.
Parameters
Returns
public static function keys(obj:Object):Array
Get an array containing the property keys of the specified object, in their
natural iteration order.
Parameters
Returns
public static function sequence(... functions):Function
Returns a function that will call each of the given functions in order.
Parameters
Returns
public static function unfuckVarargs(args:Array):Array
If you call a varargs method by passing it an array, the array
will end up being arg 1.
Parameters
Returns
public static function unit(n:int):Function
Returns a function that returns its nth argument, or undefined if there is no nth argument.
Parameters
Returns
public static function values(obj:Object):Array
Get an array containing the property values of the specified object, in their
natural iteration order.
Parameters
Returns
Copyright © 2007-2009 Three Rings Design, Inc.