= 0; i < this.length; i++)
callback(this[i], i, this);
};
why the this keyword is set to the array prototype that we are calling forEach on?
Because that how JS be
When a function is called as a method of an object, its this is set to the object the method is called on.
when we code something like [1, 2, 3].forEach(el => console.log(el)) It's like forEach is a method on the object on whatever it is called on (if the prototype is a string or number wrapping happens so its object anyway) and the this keyword will be set to object that is what we are calling the forEach method on right?
Обсуждают сегодня