As a person who has worked mainly with languages with OOP, languages with static typing, it is not quite clear to me what practical use all these troubles have with contexts in JavaScript.
Many tutorials say
You can call a function in the context of another object so that the entire inside of the object will be available to it.
and some kind of forEach is given, where for listing you need to have nothing at all.
However, if you look at the article forEach , then nowhere is there a description that he uses under the hood. Probably, you can find the source code somewhere and see what needs to be used for the iteration, however, isn't this digging in dirty implementation linen?
In other PLs, this is found on the surface in the form of some kind of interfaces.
Well, I also don’t understand why all dances with a loss of context and this is the default behavior and if I need to make the callback work normally, then I have to use the context binding.
for(...;...;...)
in its place. About "under the hood", I did not understand what you meant. But I note that in the languages about which you speak, there are simply no built-in data types, at least as similar to JS objects. Accordingly, there are no analogues forEach - MikeforEach
fromArray.prototype
described in the specification . The specification also states the following: The forEach function is intentionally generic ; it is not an Array object. Therefore, it can be transferred. - Grundy