If I want to apply a function to a single object, I can do it like this:
> 'mystr'.toUpperCase()
'MYSTR'
But if I want to do the same for an array, using map
(for example), I must do it like this:
> ['one','two','three'].map((x)=>x.toUpperCase(x))
[ 'ONE', 'TWO', 'THREE' ]
Is there a way to use this functions without the dot notation? For example
// THIS DOESN'T WORK, BUT I WANT TO ACHIEVE SOMETHING LIKE THIS
> String.toUpperCase('mystr')
'MYSTR'
> ['one','two','three'].map(String.toUpperCase)
[ 'ONE', 'TWO', 'THREE' ]
These are just examples, I don't give me specific solutions for using map
or toUpperCase
, please. I just want to know if member functions can be used as callback functions without an anonymous extra function