In keeping with Adobe's convention, Set and Map's forEach() function takes an optional 'thisObject' param
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5502 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -63,10 +63,10 @@ public class ExpiringSet extends EventDispatcher
|
||||
}
|
||||
|
||||
// from Set
|
||||
public function forEach (fn :Function) :void
|
||||
public function forEach (fn :Function, thisObject :* = null) :void
|
||||
{
|
||||
for each (var e :ExpiringElement in _data) {
|
||||
fn(e);
|
||||
fn.call(thisObject, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -263,11 +263,11 @@ public class HashMap
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function forEach (fn :Function) :void
|
||||
public function forEach (fn :Function, thisObject :* = null) :void
|
||||
{
|
||||
if (_simpleData != null) {
|
||||
for (var key :Object in _simpleData) {
|
||||
fn(key, _simpleData[key]);
|
||||
fn.call(thisObject, key, _simpleData[key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ public class HashMap
|
||||
for (var ii :int = _entries.length - 1; ii >= 0; ii--) {
|
||||
for (var e :Entry = (_entries[ii] as Entry); e != null;
|
||||
e = e.next) {
|
||||
fn(e.getOriginalKey(), e.value);
|
||||
fn.call(thisObject, e.getOriginalKey(), e.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ public class HashSet
|
||||
return (_hashMap.containsKey(o));
|
||||
}
|
||||
|
||||
public function forEach (fn :Function) :void
|
||||
public function forEach (fn :Function, thisObject :* = null) :void
|
||||
{
|
||||
_hashMap.forEach(function (key :Object, val :Object) :void {
|
||||
fn(key);
|
||||
fn.call(thisObject, key);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public interface Map
|
||||
* Call the specified function, which accepts two args: key and value,
|
||||
* for every mapping.
|
||||
*/
|
||||
function forEach (fn :Function) :void;
|
||||
function forEach (fn :Function, thisObject :* = null) :void;
|
||||
|
||||
/**
|
||||
* Returns true if this map contains no elements.
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface Set
|
||||
function contains (o :Object) :Boolean;
|
||||
|
||||
/** Call the specified function, which accepts an element as an argument. */
|
||||
function forEach (fn :Function) :void;
|
||||
function forEach (fn :Function, thisObject :* = null) :void;
|
||||
|
||||
/** Retuns the number of elements in this set. */
|
||||
function size () :int; // @TSC - should this be uint?
|
||||
|
||||
@@ -77,11 +77,11 @@ public class SortedHashMap extends HashMap
|
||||
return vals;
|
||||
}
|
||||
|
||||
override public function forEach (fn :Function) :void
|
||||
override public function forEach (fn :Function, thisObject :* = null) :void
|
||||
{
|
||||
var keys :Array = keys();
|
||||
for each (var key :Object in keys) {
|
||||
fn(key, get(key));
|
||||
fn.call(thisObject, key, get(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user