Nodejs Function Call times(n)

Here you can find the source of times(n)

Method Source Code

Function.prototype.times = function (n) {
  if (n <= 0) {
    throw new TypeError('Invalid argument');
  }//from  w ww  .ja v  a2  s. com
  var fn = this;
  return function () {
    for (var i = 0; i < n; i += 1) {
      fn.call(null, arguments);
    }
  };
};

Related

  1. partial()
    Function.prototype.partial = function(){
        var fn = this, args = Array.prototype.slice.call(arguments);
        return function(){
          var arg = 0;
          for ( var i = 0; i < args.length && arg < arguments.length; i++ )
            if ( args[i] === undefined )
              args[i] = arguments[arg++];
          return fn.apply(this, args);
        };
    ...
    
  2. map(map)
    Function.prototype.map = function (map) {
        var params = this.getParamNames();
        var fn = this;
        for (var i in params)
            fn = fn.bind({}, map[params[i]]);
        return fn;
    };
    
  3. times(f, context)
    Number.prototype.times = function(f, context){
      var n = Number(this);
      for(var i = 0; i < n; i++){
        f.call(context, i);
    };
    
  4. times(f, context)
    function Range(from, to) {
        this.from = from;
        this.to = to;
    };
    Range.prototype = {
        constructor: Range,
        includes: function(x) {
            return this.from <= x && x <= this.to;
        },
    ...