Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype

I don´t understand where does the this. key is coming from, so I can use a given array to supply to a callback function, why does the array is not stated in the parameters? can someone help?

Thanks

Your code so far


// The global variable
var s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback){
var newArray = [];
// Only change code below this line
for(let i = 0; i < this.length; i++) {
let newItem = callback(this[i]);
newArray.push(newItem);

}
// Only change code above this line
return newArray;

};

var new_s = s.myMap(function(item){
return item * 2;
});

console.log(new_s);

Challenge: Implement map on a Prototype

Functions in the prototype, also called methods, are invoked in the following way:

const arr = [1, 2, 3];

arr.map((num) => n * 3); // [3, 6, 9];

As you can see, we don’t pass array to map either rather array is referred inside map function as this. The simplest form of thinking about this is “whatever comes to the left of period”.

// The global variable
var s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback){
var newArray = ;
// Only change code below this line
for(let i = 0; i < this.length; i++) {
let newItem = callback(this[i]);
newArray.push(newItem);

}
// Only change code above this line
return newArray;

};

var new_s = s.myMap(function(item){
return item * 2;
});

console.log(new_s);

//ai{}\