返回列表

Array之for each的实现

默认分类 2014/07/06 23:06

循环转递归:

var hui = {};
hui.each = function(list, fn) {
    return list.length && fn(list.slice(0, 1)) !== 'break' && hui.each(list.slice(1), fn);
};
var l = [1, 2, 3];
hui.each(l, function(x){
    alert(x);
});
alert(l);