Functional Programming - Implement the filter Method on a Prototype

When you call your function, this is what is to the left of the dot.

[1, 1, 2, 5, 2].myFilter((el........
               ↑
            the dot

So this, when that example is called, is an array, [1, 1, 2, 5, 2].

So substitute that array for this in your logic, what’s the result?


Just for future reference, this is almost always whatever is to the left of the dot when a function is called. That “whatever” is always an object.

It is useful to override that behaviour occasionally. So JavaScript does provide a few ways to do that, to tell a function to use a different object when it’s called (these are the methods apply, call, and bind, which are attached to the Function object just like you’re attaching methods to the Array object).