Packagecom.threerings.util
Classpublic class Util

Contains a variety of utility functions.



Public Methods
 MethodDefined by
  
adapt(fn:Function, ... prepend):Function
[static] Return a var-args function that will attempt to pass only the arguments accepted by the passed-in function.
Util
  
equals(obj1:Object, obj2:Object):Boolean
[static] A nice utility method for testing equality in a better way.
Util
  
getDefault(props:Object, name:String, defaultValue:Object):Object
[static] Returns a property of an object by name if the object contains the property, otherwise returns a default value.
Util
  
init(target:Object, initProps:Object, defaults:Object = null, maskProps:Object = null):void
[static] Initialize the target object with values present in the initProps object and the defaults object.
Util
  
isPlainObject(obj:Object):Boolean
[static] Returns true if the specified object is just a regular old associative hash.
Util
  
isSimple(obj:Object):Boolean
[static] Is the specified object 'simple': one of the basic built-in flash types.
Util
  
keys(obj:Object):Array
[static] Get an array containing the property keys of the specified object, in their natural iteration order.
Util
  
sequence(... functions):Function
[static] Returns a function that will call each of the given functions in order.
Util
  
unfuckVarargs(args:Array):Array
[static] If you call a varargs method by passing it an array, the array will end up being arg 1.
Util
  
unit(n:int):Function
[static] Returns a function that returns its nth argument, or undefined if there is no nth argument.
Util
  
values(obj:Object):Array
[static] Get an array containing the property values of the specified object, in their natural iteration order.
Util
Method detail
adapt()method
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
fn:Function
 
... prepend

Returns
Function

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, "   "))
     

equals()method 
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
obj1:Object
 
obj2:Object

Returns
Boolean
getDefault()method 
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
Object
init()method 
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.
isPlainObject()method 
public static function isPlainObject(obj:Object):Boolean

Returns true if the specified object is just a regular old associative hash.

Parameters
obj:Object

Returns
Boolean
isSimple()method 
public static function isSimple(obj:Object):Boolean

Is the specified object 'simple': one of the basic built-in flash types.

Parameters
obj:Object

Returns
Boolean
keys()method 
public static function keys(obj:Object):Array

Get an array containing the property keys of the specified object, in their natural iteration order.

Parameters
obj:Object

Returns
Array
sequence()method 
public static function sequence(... functions):Function

Returns a function that will call each of the given functions in order.

Parameters
... functions

Returns
Function
unfuckVarargs()method 
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
args:Array

Returns
Array
unit()method 
public static function unit(n:int):Function

Returns a function that returns its nth argument, or undefined if there is no nth argument.

Parameters
n:int

Returns
Function
values()method 
public static function values(obj:Object):Array

Get an array containing the property values of the specified object, in their natural iteration order.

Parameters
obj:Object

Returns
Array