Javascript Array each(cb, then)

Description

Javascript Array each(cb, then)


Array.prototype.each = function(cb, then){  
   var self = this;
   var index = -1;
   var results = [];
   var next = function(result){
       if(result!=undefined) results.push(result)
       if(++index>=self.length){
           if(then!=null) then(results)
       }else{//from w  w  w.  j a  va  2  s  . co  m
           cb(self[index], next)
       }
   }
   next();
}



PreviousNext

Related