Here you can find the source of times(f, context)
// Invoke the function f this many times, passing the iteration number // For example, to print "hello" 3 times: // var n = 3; // n.times(function(n) { console.log(n + "hello"); }); Number.prototype.times = function(f, context) { var n = Number(this); for(var i = 0; i < n; i++) f.call(context, i); }; // Define the ES5 String.trim() method if one does not already exist. // This method returns a string with whitespace removed from the start and end. String.prototype.trim = String.prototype.trim || function() { if (!this) return this; // Don't alter the empty string return this.replace(/^\s+|\s+$/g, ""); // Regular expression magic }; // Return a function's name. If it has a (nonstandard) name property, use it. // Otherwise, convert the function to a string and extract the name from that. // Returns an empty string for unnamed functions like itself. Function.prototype.getName = function() { return this.name || this.toString().match(/function\s*([^()]*)\(/)[1]; };
Function.prototype.times = function (n) { if (n <= 0) { throw new TypeError('Invalid argument'); var fn = this; return function () { for (var i = 0; i < n; i += 1) { fn.call(null, arguments); }; };
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); }; ...
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; };
Number.prototype.times = function(f, context){ var n = Number(this); for(var i = 0; i < n; i++){ f.call(context, i); };
function Range(from, to) { this.from = from; this.to = to; }; Range.prototype = { constructor: Range, includes: function(x) { return this.from <= x && x <= this.to; }, ...
'use strict'; Number.prototype.times = function(fn) { if (this.valueOf()) { for (var i = 0; i < this.valueOf(); i++) { fn(i); }; function repeat(n, fn) { ...
var i = 0; Number.prototype.times = function(func) { let n = Math.round(this); if (n <= 0) return null; func(); return (n - 1).times(func); console.log(i);
Number.prototype.times = function (func) { var i; for (i = 0; i < this; i += 1) { func(); }; function random(min, max) { var floor = +min, ceil = +max; ...
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; };