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>单击按钮查看结果。</p> <br /> <br /> <input type = "button" value = "Result" onclick = "showResult();"/> </body> </html>