Prototype-enum-max
提供:Dev Guides
プロトタイプ-列挙可能なmax()メソッド
このメソッドは、最大要素(または要素ベースの計算)を返すか、列挙が空の場合は未定義を返します。 要素は直接比較されるか、最初に反復子を適用して戻り値を比較することにより比較されます。
オプションのコンテキストパラメータは、イテレータ関数がバインドされるものです。 使用する場合、イテレータ内の_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>