Prototype - Enumerable invoke() 方法

此方法是针对 each() 或 collect() 方法的常见用例的优化。对所有元素调用具有相同潜在参数的相同方法。

语法

Iterator.invoke(methodName[, arg...]);

返回值

返回方法调用的结果。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            alert(['hello', 'world', 'cool!'].invoke('toUpperCase') );
            // Returns ['HELLO', 'WORLD', 'COOL!'];

            alert(['hello', 'world', 'cool!'].invoke('substring', 0, 3));
            // Returns ['hel', 'wor', 'coo']
         }
      </script>
   </head>

   <body>
      <p>单击按钮查看结果。</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

输出

prototype_enumerating.html