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 trialSoheb Vahora
9,229 PointsWhy is it book.out = true, instead of book.out(true)?
In the Patron class, when changing the boolean value of book.out, why aren't we invoking the setter function with the argument true/false? I find it weird that its an equal sign instead of a out function call.
1 Answer
Robert Manolis
Treehouse Guest TeacherHi Soheb Vahora, it depends on whether you're dealing with a property of the book object, or a method of the book object. If out
were a method that accepted a boolean as argument, then could say: book.out(true);
But if you're dealing with a property that doesn't have a setter, then you'd update its value with just an assignment operator: book.out = true;
Hope that helps.
Adam N
70,280 PointsAdam N
70,280 PointsAre you sure about this: "Or if out were a property that had a setter defined for updating it, then you could do something similar"
Wouldn't this code work if that were true? It doesn't.
Robert Manolis
Treehouse Guest TeacherRobert Manolis
Treehouse Guest TeacherGreat catch, Adam N! You're absolutely right. Updating with the setter would still use the assignment operator. Thanks for catching that. I'll update my post so it's not spreading misinformation. There's too much of that out there already.
Marco Ricci
Front End Web Development Techdegree Graduate 23,880 PointsMarco Ricci
Front End Web Development Techdegree Graduate 23,880 PointsSo? i really don't understand. We are going to use the SET method to set the property, so we should use book.out(true); Pls someone explain that!