I was looking at the documentation on the map function on the Mozilla developer page and have a question about one of the examples.
Here's the link to the dev page. I'm looking at the "using map generically" example. I've also included the code below:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
var map = Array.prototype.map;
var a = map.call('Hello World', function(x) { return x.charCodeAt(0); });
// a now equals [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]
Firstly, what do they mean by using map "generically". I'm guessing this has to do with
var map = Array.prototype.map;
One of the things that is still new to me is prototype in JS. In my own words, what I understand is that it can be used to change the way a function works and that it sort of works in a way that adds the functionality of classes to JS.
Anyway, what is this storing in the map variable? How come they can now pass a string to the args of the map function? What is the point of calling the map function on map instead of doing something like:
var a = 'Hello World'.split('').map( function(x) { return x.charCodeAt(0); });