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 trialJuneau Lim
13,362 PointsWhen do you use () when calling a method and when you don't?
It's a bit confusing. :-( When can I omit / or should omit parentheses and when not?
2 Answers
Steven Parker
231,172 PointsYou always put parentheses after a method name to call the method.
The only time you're likely to use a function/method name without the parentheses is to pass it as a callback to another function.
KRIS NIKOLAISEN
54,971 PointsYou always use () to invoke a function. Without () the function definition is returned.
Juneau Lim
13,362 PointsNow I am studying OOP part, and when it is said that when I use setter/getter, I am making ones with the same name and call it just as if they are a parameter, without ().
I also have learned a little bit of Vue.js, and I remember that sometimes I call methods without (), but can't remember what I did it for.
It that the only case of getter/setter?
Juneau Lim
13,362 PointsJuneau Lim
13,362 PointsThank you. That makes sense. When I googled it, the autocomplete was javascript callback hell. Hilarious.