I was recently looking into Javascript prototypes and how they work. Therefore, I stumbled upon the following code:
String.prototype.repeatify = String.prototype.repeatify || function(times){
var str = '';
for(var i = 0; i < times; i++){
str += this;
}
return str;
}
alert("hello".repeatify(5));
Now I understand every aspect of how this works and why it is done this way, what I am not understanding is what or which circumstances deem this approach not recommendable, not correct or what about this should I be aware that could be a potential problem.
For your information, I already looked into other StackOverflow questions regarding this subject, but none of the answers given where clear to me, I hope it is alright if the community can answer based of the above code snippet and expand from there.
EDIT:
For future reference, readers also refer to: Extending native builtins