Prototype - $R() 方法
$R() 函数只是 new ObjectRange(lowerBound, upperBound, excludeBounds) 的简写。
语法
$R(start, end[, exclusive = false]);
此处,start 是范围的起始元素,end 是范围的最后一个元素。如果 exclusive 标志设置为 false,则它将包含结束元素,否则它将不包含在范围内。
返回值
范围对象。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function ShowValues() {
var range = $R(10, 20, false);
range.each(function(value, index) {
alert(value);
});
}
</script>
</head>
<body>
<p>Click "Show Value" button to see the result</p>
<form>
<input type = "button" value = "Show Value" onclick = "ShowValues();"/>
</form>
</body>
</html>
输出
更多示例
以下语句返回 true 值 −
$R(0, 10).include(10);
以下语句返回字符串"0, 1, 2, 3, 4, 5" −
$A($R(0, 5)).join(', ');
以下语句返回字符串"aa, ab, ac, ad, ae, af, ag, ah" −
$A($R('aa', 'ah')).join(', ');
以下语句返回 false −
$R(0, 10, true).include(10);
以下语句将被调用 10 次,值 = 0 到 9 −
$R(0, 10, true).each(function(value) {
// 调用 10 次,值 = 0 到 9
});
prototype_utility_methods.html

