I will be grateful if anyone looks at how I understand Solution 1 (with forEach) and say whether such an understanding is correct, especially in understanding what the keyword
this is doing there.
This is a prototype of a method called myMap. The method calls a certain function named “callback” (it could be any other name), which:
- creates a
- using the key word
this, it sets the property, as usual in a constructor, and in this case the property is the function (
- it iterates through [some] array using the forEach method;
- on each element of [some] array it executes the function named “callback”;
- the result of the every function execution step is pushed into the created
- the method returns
When we call the myMap() method on the source array
s, it performs all these actions, plus the
item*2, in this example, and returns the general result.