- 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
广告