String.prototype.repeat = function(count) { if (count < 1) return ''; var result = '', pattern = this.valueOf(); while (count > 1) { if (count & 1) result += pattern; count >>>= 1, pattern += pattern; } return result + pattern; };
info at phpclasses dot org