Arrays: every, filter, map, some

Nearly all callback methods to a filter-based method only specify that the type of object to be inspected be of type Object. While this certainly allows for the greatest flexibility in what is stored in the ordinal list, this doesn’t give you much control over chasing down RTE’s or allow for IDE ease of use in auto-completion.

There is noting out there which says you are not allowed to specify a cast to a higher order object since this callback method is NOT in the fixed properties signature for the class. While these methods do have method closure in which you are not forced to wrap it in a Delegate as in the days of old, it’s not much different than a

function.apply(this, [parameters]);

So, what this buys you is some flexibility that you may or may not have been made aware of when it comes to method signature (overloading the method signature is still off limits though, since the ‘apply‘ is done internally). For example: if you have a list of objects that you know are of a specific class, why not cast that generic item:Object as item:Car, item:Fruit, or item:UserRolePolicy? By going with a specific cast, you now have enabled your IDE of choice to pin-down a specific fixed properties class which not only aids in debugging, but auto-completion support as well.

var carCollection:Array; var currentBrand:String ='Pontiac'; carCollection.filter(carsByBrand); function carsByBrand(item:Car, index:int, source:Array):Boolean {     return item.brand ==currentBrand; }

Happy filtering.