返回到:Prototype – 枚举
此方法返回最大元素(或基于元素的计算),如果枚举为空,则返回未定义。元素要么直接比较,要么首先应用迭代器并比较返回值。
可选的上下文参数是迭代器函数将绑定到的内容。如果使用,迭代器中的this关键字将指向参数给定的对象。
语法
Iterator.max(context);
返回值
返回最大值。
例子
HTML
x
32
32
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
alert("$R(1,10).max() : " + $R(1,10).max() );
9
// Returns 10
10
11
function Person(name, age) {
12
this.name = name;
13
this.age = age;
14
}
15
var john = new Person('John', 20);
16
var mark = new Person('Mark', 35);
17
var daisy = new Person('Daisy', 22);
18
19
alert("Max Age:"+[john, mark, daisy].max(function(person) {
20
return person.age ;
21
}) );
22
}
23
</script>
24
</head>
25
26
<body>
27
<p>Click the button to see the result.</p>
28
<br />
29
<br />
30
<input type = "button" value = "Result" onclick = "showResult();"/>
31
</body>
32
</html>
返回到:Prototype – 枚举
阅读剩余 48%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8600.html