原型 - 可列舉任何()方法
此方法確定是否至少有一個元素直接或透過提供的迭代器計算為布林值 true。
可選的 context 引數是迭代器函式將繫結到的內容。如果使用,迭代器內部的 this 關鍵字將指向引數給出的物件。
語法
Iterator.any([context]);
返回值
如果迭代器中的至少一個值是 true,則返回布林值 true。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
alert( "[].any() : " + [].any() );
// false (empty arrays have no elements)
alert("$R(0, 2).any() : " + $R(0, 2).any() );
// true (on the second loop cycle, 1 is true-equivalent)
alert("[0, 1, 2].any() : " + [0, 1, 2].any() );
// true (with 1 and 2 loop cycle is true )
alert([9, 10, 15].any(function(n) { return n >= 10; }) );
// true (the iterator will return true more than 10 )
}
</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
廣告