Prototype-enum-all

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

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

このメソッドは、すべての要素がブール値に相当するかどうかを、直接または指定された反復子による計算によって決定します。

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

構文

Iterator.all([context]);

戻り値

イテレータのすべての値がtrueの場合、ブール値のtrue値を返します。

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

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

            alert("$R(1, 5).all() : " + $R(1, 5).all() );
           //true (all values in [1..5] are true-equivalent)

            alert("[0, 1, 2].all() : " + [0, 1, 2].all() );
           //false (with only one loop cycle: 0 is false-equivalent)

            alert([9, 10, 15].all(function(n) { return n >= 10; }) );
           //false (the iterator will return false on 9)
         }
      </script>
   </head>

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

出力