I am trying to write a function which returns the middle character of a string. I want it to work like the code below :
"123456789".midChar(); // Returns 5
"hello".midChar(); // returns 1
"test".midChar(); // returns e
I want to know how can I access the string if the function takes no parameters? How can I refer to the strings inside of the function to be able to manipulate it? For example "123456789"
What have I done before asking this question?
I read about prototypes and understood how I can add methods to the array and string prototype. I tried to find the implementation of String.prototype.charAt() and several other ones to understand how it's built, but couldn't find one. All i was able to find is Reduce, ForEach and several other Array methods, but that wasn't very helpful to my case.
this.