首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

prototypejs each方法,该怎么处理

2012-02-14 
prototypejs each方法有谁能给解释下prototype的each方法就是那个传说是模拟接口实现的越详细越好![解决办

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]

热点排行
Bad Request.