Prototype - Enumerable all() 方法
此方法确定所有元素是否布尔值等同于 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(空数组没有元素) alert("$R(1, 5).all() : " + $R(1, 5).all() ); // true([1..5] 中的所有值都为真等价值) alert("[0, 1, 2].all() : " + [0, 1, 2].all() ); // false(只有一个循环周期:0 为假等价值) alert([9, 10, 15].all(function(n) { return n >= 10; }) ); //false(迭代器将在 9 上返回 false) } </script> </head> <body> <p>单击按钮查看结果。</p> <br /> <br /> <input type = "button" value = "Result" onclick = "showResult();"/> </body> </html>