javascript - 怎么理解new Array(count + 1).join(this)
巴扎黑
巴扎黑 2017-04-10 13:12:15
0
1
326

重复字符串方法

 String.prototype.repeat = function(count) {
      return new Array(count + 1).join(this);
    };

'test'.repeat(3);//testtesttest

巴扎黑
巴扎黑

Antworte allen(1)
巴扎黑

一个长度为n+1的空数组用string去拼接成字符串,不就成了nstring的重复了么

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage