Gone thru the livedocs but the examples are quite sparse. Can anyone give me some good 'real world' examples of when and why you might use the map and filter methods of the new Vector class in Actionscrip开发者_开发技巧t?
The Vector filter
and map
methods work just the same as the methods in the Array class of the same name. Check the following two pages for filter examples for arrays (they work just the same for the Vector class):
http://troyworks.com/blog/2007/12/16/as3-arrayfilter-r0xr/ http://www.onebyonedesign.com/tutorials/array_methods/
I couldn't find any decent as3 map examples, but the jQuery equivalent explains how/why you would use it fairly well: http://api.jquery.com/jQuery.map/
As for real world uses, filter is unbelievably useful. Suppose you have a Vector filled with Employee objects. You can use the filter
method as a non-destructive way to get all the Employees whose name starts with "A", or whose salary is greater than $50,000. The map
function is similar, but it creates a new Vector and allows you to alter the objects, so you could potentially cast each Employee as a new type, such as HighlyPaidEmployee.
精彩评论