Nodejs Function Call times(cb)

Here you can find the source of times(cb)

Method Source Code

// Ruby = 5.times { |i| puts i }
// JS   = (1).times(function(i){console.log(i);})
Number.prototype.times = function(cb) {
  var i = -1;/*from  w ww .  j  a v a 2  s.  com*/
  while (++i < this) { cb(i); }
  return +this;
};

Related

  1. times(callback)
    Number.prototype.times = function(callback){
      for (var s = this - 1; s >= 0; s--){
        callback.call(this,s);
      };
    
  2. times(callback)
    Number.prototype.times = function(callback){
        for (var i = 0; i < this; i++) {
          callback();
    };
    
  3. times(callback)
    Number.prototype.times = function(callback) {
      for (var i = 0; i < this; i++) {
        callback.call(this, i);
      return this;
    };
    
  4. times(callback)
    Number.prototype.times = function(callback) {
      var i;
      if(typeof callback === 'undefined') {
        var array = [];
        for(i = 0; i < this; i++) array.push(i);
        return array;
      }  else if(typeof callback === 'function')  {
        for(i = 0; i < this; i++) callback(i);
      } else {
    ...
    
  5. times(cb)
    Number.prototype.times = function (cb) {
      var i = -1;
      while (++i < this) {
        cb(i);
      return +this;
    };
    
  6. times(cb)
    Number.prototype.times = function(cb) { 
      for (var i = 0; i < this; i++) cb(i);
    };
    
  7. times(object)
    Number.prototype.times = function(object){
      var l = [];
      this.timesRepeat(function(){l.push(object)});
      return l;
    
  8. timesDo(callback)
    Number.prototype.timesDo = function (callback) {
        if (callback) {
            for (var i = 0; i < this; i++) {
                callback.call();
    };