ES6 version repeatify String.prototype.repeatify = function (times = 1) { console.log(this) // String {"abx"} return [...``.padStart(times, ` `)].map((item, i) => item = this).join(``); }; `abx`.repeatify(3); // "abxabxabx"
https://stackoverflow.com/a/62155265/5934465