Nodejs Function Call times(args)

Here you can find the source of times(args)

Method Source Code

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))
      }//from w  ww  .  ja  v a  2  s .  c  om
};


function Bye(num) {console.log(num)};
function Hello() {console.log("hello");}
function Something(num, num2) {console.log(num, num2);}

(3).times(Hello, 4, 5, 6);
(2).times(Bye, 3);
(2).times(Something, 2, 3);

Related

  1. times(iterator)
    Number.prototype.times = function (iterator) {
      for (var i = 0; i < this; i++) {
        iterator(i);
    };
    
  2. 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; };
    
  3. times(iterator, context)
    Number.prototype.times = function(iterator, context) {
      for(var i = 0; i < this; i++) {
        iterator.call(context, i);
      return i;
    };
    
  4. times(action)
    "use strict";
    Number.prototype.times = function(action) {
      var i;
      for (i = 1; i <= this; i++) {
        action();
    };
    (5).times(function () { console.log("OMG!"); });
    
  5. times(action)
    Number.prototype.times = function(action) {
      var counter = this
      while (counter-- > 0)
        action()
    
  6. times(blk)
    Number.prototype.times = function(blk){
      for (var i = 0 ; i < this ; ++i){
        blk.apply(i, [i]);
      return this;
    
  7. 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();
    };
    
  8. times(callback)
    Number.prototype.times = function(callback){
      for (var s = this - 1; s >= 0; s--){
        callback.call(this,s);
      };
    
  9. times(callback)
    Number.prototype.times = function(callback){
        for (var i = 0; i < this; i++) {
          callback();
    };