Nodejs Function Call times(callback)

Here you can find the source of times(callback)

Method Source Code

Number.prototype.times = function(callback) {
  var i;/*from  w ww.  j a  va  2 s .c  o m*/
  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 {
    throw new Error("Wrong .times usage");
  }

  return null;
};

Related

  1. times(blk)
    Number.prototype.times = function(blk){
      for (var i = 0 ; i < this ; ++i){
        blk.apply(i, [i]);
      return this;
    
  2. times(callback)
    Number.prototype.times = function(callback) {
      if (typeof callback !== 'function') {
        throw new TypeError(callback + ' is not a function');
      for (let i = 0; i < this; i++) {
        callback();
    };
    
  3. times(callback)
    Number.prototype.times = function(callback){
      for (var s = this - 1; s >= 0; s--){
        callback.call(this,s);
      };
    
  4. times(callback)
    Number.prototype.times = function(callback){
        for (var i = 0; i < this; i++) {
          callback();
    };
    
  5. times(callback)
    Number.prototype.times = function(callback) {
      for (var i = 0; i < this; i++) {
        callback.call(this, i);
      return this;
    };
    
  6. times(cb)
    Number.prototype.times = function (cb) {
      var i = -1;
      while (++i < this) {
        cb(i);
      return +this;
    };
    
  7. times(cb)
    Number.prototype.times = function(cb) {
      var i = -1;
      while (++i < this) { cb(i); }
      return +this;
    };
    
  8. times(cb)
    Number.prototype.times = function(cb) { 
      for (var i = 0; i < this; i++) cb(i);
    };
    
  9. times(object)
    Number.prototype.times = function(object){
      var l = [];
      this.timesRepeat(function(){l.push(object)});
      return l;