代码改变世界

添加一个js扩展方法

2018-06-17 13:18  改吧  阅读(1375)  评论(0编辑  收藏  举报


String.prototype.repeatify=String.prototype.repeatify || function(times){
var str='';
for(var i=0;i<times;i++){
console.log('this',this)
// this指向调用这个函数的对象
str+=this;
}
return str
}

 

'hello'.repeatify(3)======>'hellohellohello'