Is it possible to work with String.prototype?

0 like 0 dislike
Good afternoon.

Let's say I want the function fn () that can be applied like this:
console.log('Hello'.fn()) //HelloolleH

Never occurred anything better than:
String.prototype.fn = function() { return this + this.split(").reverse().join("); }

Question: is this the right way to deal with String.prototype, and if not, how such to implement?
by | 5 views

2 Answers

0 like 0 dislike
Tip for the future, don't touch never the prototypes of String, Array of it.d. If you must, then it is better to create a class, but in the original prototypes do not go better.
0 like 0 dislike
Question from the category of "can I ride clinging to the back of the tram"

Do the laws of physics do not forbid you this. But it is inconvenient, unsafe, and the police will swear.

And with the modification of the original prototypes, all technically it can be done, but it's not a good idea for everyday use.

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked Apr 9, 2019 by Resident234
110,608 questions
257,186 answers
33,947 users