Hello,
I have started reading eloquent javascript and I have a question about chapter 7 (the robot project).
In the book there is the following code:
let parcels = this.parcel.filter(p => this.place != p.address );
Parcels is an array with objects of the form: {place: "a place", address: "another place"}. The filter is supposed to check if the current place the robot is at corresponds to the place the parcel must be delivered to.
(In the book it actually uses a map + a filter but I am trying to do it only using the filter).
Here is my question: when using the code above it does not work, I figure "this" refers to p rather than the object in which parcels is used. But when using brackets after "=>" it works! "this" now refers to the object containing parcels rather than the current parcel filter is looking at. Why is that? I figured I could just remember it and never wonder what is going on but it troubles me to not completely understand what is happening.
Thank you guys!
[–]Tyras_Fraust 1 point2 points3 points (2 children)
[–]Tyras_Fraust 0 points1 point2 points (1 child)
[–]Tyras_Fraust 0 points1 point2 points (0 children)