原型 - Enumerable all() 方法
此方法确定是否所有元素都是 boolean 等效值为 true,无论是直接进行还是通过提供的迭代器计算。
可选的 context 参数是迭代器函数将绑定到的内容。如果使用,则迭代器内的 this 关键字将指向参数给定的对象。
语法
Iterator.all([context]);
返回值
如果迭代器中的所有值均为 true,则返回布尔 true 值。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
alert( "[].all() : " + [].all() );
// true (empty arrays have no elements )
alert("$R(1, 5).all() : " + $R(1, 5).all() );
// true (all values in [1..5] are true-equivalent)
alert("[0, 1, 2].all() : " + [0, 1, 2].all() );
// false (with only one loop cycle: 0 is false-equivalent)
alert([9, 10, 15].all(function(n) { return n >= 10; }) );
//false (the iterator will return false on 9)
}
</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
广告