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 Introducing ES2015 Classes Getter and Setter Methods

Constructor placement / location?

In every video Guil has the constructor near the bottom of the class with the methods before. For me it seems more natural to have the constructor first, at the top. The code seems to work both ways.

Is the way Guil defines a constructor the preferred convention? Or does it not matter?

2 Answers

Steven Parker
Steven Parker
231,275 Points

Technically, it doesn't matter.

And i'm not sure if there's an actual "convention"; but like you, I also prefer to place constructors at the top.

lauralouise
lauralouise
14,853 Points

Just a note about this -- it technically doesn't matter where the constructor goes, but I've noticed that Workspaces does not like it if the constructor goes at the very top. Not sure why this is. If you put your constructor at the top, with no functions above it, the syntax highlighting (i.e. the different colors) goes all wonky.