Prototype-expressing-ranges

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

プロトタイプ-表現範囲

プロトタイプ範囲は、値の間隔を表します。 範囲を取得する好ましい方法は、 $ R ユーティリティ関数を使用することです。

次のような単純な構文を使用して、値の広い範囲を作成できます-

$R(1, 10).inspect();

$R('a', 'e').inspect();

これは、次の結果を生成します-

['1, 2, 3, 4, 5, 6, 7, 8, 9, 10']

['a', 'b', 'c', 'd', 'e']

include()メソッド

このメソッドは、値が範囲に含まれているかどうかを決定します-

構文

Range.include(value);

戻り値

値が含まれている場合はtrueを返し、そうでない場合はfalseを返します。

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

      <script>
         function showResult() {
            alert ( "Test 1 : " + $R(1, 10).include(5));
           //Returns true

            alert ( "Test 2 : " + $R('a', 'h').include('x'));
           //Returns flase
         }
      </script>
   </head>

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

出力