I ran into this error of "Cannot read property 'localeCompare' of undefined"
when I was trying to convert a string function of compare(String, String) to String.compare(String)
let compare = (y, x) => y.localeCompare(x) == 0 ? true : false; //This works
let gender = x => compare("male", x) || compare("female", x); //This works
String.prototype.compareTruthy = (x) => {
this.localeCompare(x) == 0 ? true : false;
}
"male".compareTruthy("male") //This does not work, why?
I wanted to re-use this compareTruthy function for any other string comparisons I might have later on.
What am I missing in my understanding?