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

JavaScript

Help 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

Steven Parker
Steven Parker
243,266 Points

Which video? Could you post a link to it?

2 Answers

Steven Parker
Steven Parker
243,266 Points

This 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.

Steven Parker
Steven Parker
243,266 Points

Hey .. 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?

Yes. That helped. I would love to know any resources I can read to further go in-depth with explanations.

Steven Parker
Steven Parker
243,266 Points

It's a clever implementation, but of pretty basic concepts. Anything about JavaScript Objects or "Object Oriented JavaScript" would cover the concepts being used here.

Oh ok. Thank you Steven. I'm headed to that course after this course I'm currently on.