I was looking at a question yesterday in which the poster was asking how to convert the case of an array's contents. I know that I can pass a reference to a function to map like:
function appendText (el){
return el += ' - appended text';
}
['a','b'].map(appendText); //["a - appended text", "b - appended text"]
But when I tried with
array.map(String.toUpperCase);
array.map(String.prototype.toUpperCase);
I get the error
Uncaught TypeError: String.prototype.toUpperCase called on null or undefined
Which makes it sound like the method isn't getting passed the element map
would, as I understand it, be passing. Why doesn't this work?