Nodejs Function Call times(iterator, context)

Here you can find the source of times(iterator, context)

Method Source Code

/**// w  w w. ja va  2 s  .  c  om
 * Calls iterator the specified number of times, passing in the number of the
 * current iteration as a parameter: 0 on first call, 1 on the second call, etc.
 *
 * @param {Function} iterator The iterator takes a single parameter, the number
 * of the current iteration.
 * @param {Object} [context] The optional context parameter specifies an object
 * to treat as <code>this</code> in the iterator block.
 *
 * @returns The number of times the iterator was called.
 * @type Number
 */
Number.prototype.times = function(iterator, context) {
  for(var i = 0; i < this; i++) {
    iterator.call(context, i);
  }

  return i;
};

Related

  1. times(func, scope)
    Number.prototype.times = function(func, scope) {
      var i, v, _results;
      v = this.valueOf();
      i = 0;
      _results = [];
      while (i < v) {
        func.call(scope || window, i);
        _results.push(i++);
      return _results;
    };
    
  2. times(handler)
    Number.prototype.times = function(handler) {
      var index = 0;
      while(index < this) handler(index++);
      return this
    };
    
  3. times(iterator)
    Number.prototype.times = function(iterator) {
      var index = 0;
      while(index < this) iterator(index++);
      return this
    };
    
  4. times(iterator)
    Number.prototype.times = function (iterator) {
      for (var i = 0; i < this; i++) {
        iterator(i);
    };
    
  5. times(iterator, context)
    Number.prototype.times = function(iterator, context) {
      for (var i = 0; i < this; i++) iterator.call(context, i);
    };
    Number.prototype.seconds = function() { return this * 1000; };
    Number.prototype.minutes = function() { return this * 1000 * 60; };
    Number.prototype.hours   = function() { return this * 1000 * 3600; };
    Number.prototype.days    = function() { return this * 1000 * 3600 * 24; };
    
  6. times(action)
    "use strict";
    Number.prototype.times = function(action) {
      var i;
      for (i = 1; i <= this; i++) {
        action();
    };
    (5).times(function () { console.log("OMG!"); });
    
  7. times(action)
    Number.prototype.times = function(action) {
      var counter = this
      while (counter-- > 0)
        action()
    
  8. times(args)
    Number.prototype.times = function(args) {
      var args = Array.prototype.slice.apply(arguments);
      for(var i = 0; i < this; i++) {
          args[0].apply(null, args.slice(1))
    };
    function Bye(num) {console.log(num)};
    function Hello() {console.log("hello");}
    function Something(num, num2) {console.log(num, num2);}
    ...
    
  9. times(blk)
    Number.prototype.times = function(blk){
      for (var i = 0 ; i < this ; ++i){
        blk.apply(i, [i]);
      return this;