Prototype-hash-merge

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

プロトタイプ-merge()メソッド

このメソッドはオブジェクトをハッシュにマージし、そのマージの結果を返します。 キーが重複すると上書きされます。

構文

hash.merge(object);

戻り値

結果のマージされたハッシュを返します。

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

      <script>
         function showResult() {
            var h = $H({ name: 'Prototype', version: 1.6 });
            h = h.merge({ version: 1.6, author: 'Sam' });
            h.each(function(pair) {
               alert(pair.key + ' = "' + pair.value + '"');
            });
         }
      </script>
   </head>

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

出力