- 原型教程
- 原型 - 首頁
- 原型 - 簡要概述
- 原型 - 有用的功能
- 原型 - 實用工具方法
- 原型 - 元素物件
- 原型 - 數值處理
- 原型 - 字串處理
- 原型 - 陣列處理
- 原型 - 雜湊處理
- 原型 - 基本物件
- 原型 - 模板
- 原型 - 列舉
- 原型 - 事件處理
- 原型 - 表單管理
- 原型 - JSON 支援
- 原型 - AJAX 支援
- 原型 - 表達範圍
- 原型 - 週期性的執行
- 原型有用資源
- 原型 - 快速指南
- 原型 - 有用的資源
- 原型 - 討論
原形 - 可列舉 map() 方法
此方法返回對每個元素應用迭代器後的結果。此方法別名為 collect() 方法。
語法
Iterator.map([context]);
返回值
返回對每個元素應用迭代器後的結果
例項
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
alert( $R(1,5).collect(function(n) {return n * n;}) );
// returns [1, 4, 9, 16, 25]
}
</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
廣告