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 trial
Edwin Billa
Full Stack JavaScript Techdegree Student 4,690 PointsHelp on syntax "nameActions[action]()"
Hello, I'm confused about this syntax "nameActionsaction" used in the video, Is there any resource where I can read and have in-depth understanding about it. Thanks
https://teamtreehouse.com/library/refactor-2-readable-branching-logic
2 Answers
Steven Parker
243,266 PointsThis is a bit of a guess...
Since I'm not even sure what course this is for, but just by looking at nameActions[action]() I would guess that nameActions is an object that contains a number of method (function) properties. And then action would be a parameter passed to it that contains the name of the specific method to use. Finally the parentheses () cause that method to be invoked.
Does that help? If not, please post more specifics about the course and video in question.
Edwin Billa
Full Stack JavaScript Techdegree Student 4,690 Pointshttps://teamtreehouse.com/library/refactor-2-readable-branching-logic Sorry this is the video
Steven Parker
243,266 PointsHey .. it looks like my guess was correct. The code in the video uses the text written on the button as the action to choose which method to invoke.
Did my explanation cover what you were looking for?
Edwin Billa
Full Stack JavaScript Techdegree Student 4,690 PointsYes. That helped. I would love to know any resources I can read to further go in-depth with explanations.
Steven Parker
243,266 PointsIt's a clever implementation, but of pretty basic concepts. Anything about JavaScript Objects or "Object Oriented JavaScript" would cover the concepts being used here.
Edwin Billa
Full Stack JavaScript Techdegree Student 4,690 PointsOh ok. Thank you Steven. I'm headed to that course after this course I'm currently on.
Steven Parker
243,266 PointsSteven Parker
243,266 PointsWhich video? Could you post a link to it?