在MDN doc for String.prototype.repeat中,polyfill具有以下代码行:
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
'use strict';
if (this == null)
throw new TypeError('can\'t convert ' + this + ' to object');
这怎么可能为空?
喜欢这个:
String.prototype.repeat.call()
const test = 'test'.repeat;
test();