DEV Community

Cover image for Adding our own custom methods in JavaScript prototype class
Amir Sohel
Amir Sohel

Posted on • Updated on

Adding our own custom methods in JavaScript prototype class

I have a question regarding JavaScript.

is this good practice to add our own method in prototype class

like I have added my own custom method in String prototype class like this

String.prototype.mirror = function () {
  let str = this.toString() ;
 return str.split('').reverse().join('')
}
Enter fullscreen mode Exit fullscreen mode

and now i am using my own method with any string value like

"hello".mirror()
"olleh"

Top comments (0)