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

重复字符串方法

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

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

巴扎黑
巴扎黑

全部回覆(1)
巴扎黑

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

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板