Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJamie Wyton
3,011 Pointssetter.....?
computed properties....I just don't get this. in the video Jeremy deletes the setter to make it a computed property and says that every time the _path field is changed the property updates Location. How is this possible? I don't see any relation between the two fields in this code. In order for the property to be updated in alignment with another field surely it has to be told to do so?!
2 Answers
Steven Parker
231,198 PointsThere is no longer any field associated with Location.
After the changes are made, any time Location is referenced, a call is made to GetLocationAt using _path and _pathstep. There is no longer any field or auto-property to update.
Christopher Debove
Courses Plus Student 18,373 PointsMore importantly, he did not say that the Location property would be automatically updated, but that it would always be accurate.
In fact calling the property getter Location will call GetLocationAt on the private _path field with _pathStep as argument. This is what's called a "Computed property". It computes it result from other data.