日期:2014-05-16  浏览次数:20404 次

prototypejs each方法
有谁能给解释下prototype的each方法
就是那个传说是模拟接口实现的

越详细越好!

------解决方案--------------------
each([1,2,3] ,function(i){alert(i)}) 

?是想要这样的吗?
------解决方案--------------------
['one', 'two', 'three'].each(function(s) {
alert(s);
});
[ 'hello', 'world'].each(function(s, index) {
alert(index + ': ' + s);
});
// alerts -> '0: hello' then '1: world'
// This could be done better with an accumulator using inject, but humor me
// here...
var result = [];
$R(1,10).each(function(n) {
if (0 == n % 2)
throw $continue;
if (n > 6)
throw $break;
result.push(n);
});
// result -> [1, 3, 5]