Prototype-enum-any

提供:Dev Guides
移動先:案内検索

プロトタイプ-列挙可能なany()メソッド

このメソッドは、少なくとも1つの要素が、直接または指定された反復子による計算を通じてブール値に相当するかどうかを判断します。

オプションのコンテキストパラメータは、イテレータ関数がバインドされるものです。 使用する場合、イテレータ内の_this_キーワードは、引数で指定されたオブジェクトを指します。

構文

Iterator.any([context]);

戻り値

イテレータの少なくとも1つの値がtrueの場合、ブール値のtrue値を返します。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showResult() {
            alert( "[].any() : "  + [].any() );
           //false  (empty arrays have no elements)

            alert("$R(0, 2).any() : " + $R(0, 2).any() );
           //true (on the second loop cycle, 1 is true-equivalent)

            alert("[0, 1, 2].any() : " + [0, 1, 2].any() );
           //true (with 1 and 2 loop cycle is true )

            alert([9, 10, 15].any(function(n) { return n >= 10; }) );
           //true (the iterator will return true more than 10 )
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br/>
      <br/>
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

出力