クラスのsome()
, every()
(およびforEach()
) メソッドには 2 つのパラメーターがあります。Array
callback
各アイテムで実行される関数。基準に基づいて true または false を返す必要があります
thisObject
コールバック関数に指定できるオプションのオブジェクトです。関数内では、this
キーワードを使用してオブジェクトを参照できます。このパラメーターを省略すると、コールバック関数でクロージャーを形成できます。
コールバック関数のシグネチャは次のとおりです。
private var callback:Function = function(currentItem:Object, currentIndex:int, theEntireArray:Array):Boolean
{
// your logic here returns true/false based on your critera
}
あなたのシナリオでは、おそらく次のsome()
ような方法を使用できます。
private var comparisonString:String;
private function showTheExampleCode()
{
for each (var str:String in newHand)
{
// comparisonString will be used in the closure
// maybe you can just use str in the closure instead?
comparisonString=str;
if (hand.some(callback))
{
// at least one match was found, do something
}
}
}
private var callback:Function(currentItem:Object, currentIndex:int, array:Array):Boolean
{
// current item is a Card object (you probably do not have to cast it)
return Card(currentItem).visible && Card(currentItem).str == comparisonString;
}