- Prototype 教程
- Prototype - 首頁
- Prototype - 簡要概述
- Prototype - 有用特性
- Prototype - 實用方法
- Prototype - Element 物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - Hash 處理
- Prototype - 基本物件
- Prototype - 模板
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表達範圍
- Prototype - 週期執行
- Prototype 有用資源
- Prototype - 快速指南
- Prototype - 有用資源
- Prototype - 討論
Prototype - Enumerable max() 方法
該方法返回最大元素(或基於元素的計算),如果列舉為空,則返回 undefined。元素要麼直接比較,要麼先應用迭代器並比較返回的值。
可選的 context 引數是指迭代器函式將繫結到的內容。如果使用,則迭代器內部的 this 關鍵字將指向引數給定的物件。
語法
Iterator.max(context);
返回值
返回最大值。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
alert("$R(1,10).max() : " + $R(1,10).max() );
// Returns 10
function Person(name, age) {
this.name = name;
this.age = age;
}
var john = new Person('John', 20);
var mark = new Person('Mark', 35);
var daisy = new Person('Daisy', 22);
alert("Max Age:"+[john, mark, daisy].max(function(person) {
return person.age ;
}) );
}
</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
廣告