原型——可遍历的 invoke() 方法
该方法是每种() 方法或 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>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
输出
prototype_enumerating.htm
广告