Good Question:
Array is a constructor function to create arrays.
If you type Array in browser console you will get a function definition, something like
function Array() { [native code] }
While if you type Array.prototype in browser console you will get an empty array i.e [ ]
i.e. an Array object.
Consider this excerpt
function a(){
console.log('hi');
function b(){console.log('b');}
function c(){console.log('c');}
return {b:b,c:c,d:this}
}
When you type d = new a();
Then d is an object having two properties which are functions i.e. b and c and you can call
>> d.b() //logs b
>> d.c() //logs c
But you cannot call
a.b() or a.c()
// since function b and c is not property of a.
So just as function b and c are defined in function a. Similarly function map is defined in function Array.
So you cannot call Array.map()
but you have to get an object of Array and call map function on it.
Array.prototype
gives us an Array object
Therefore they are using Array.prototype.map.call(a,func)
Sorry for long explanation. Hope it benefits.:)
Array.map
is available by default, you can also dofunction getLinks() { return [link.href for (link of document.querySelectorAll('h3.r a')]; }
. :)