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 trialChristopher Aporta
24,258 PointsWhen creating a Constructor Function, is it best practice to use a Function Declaration or a Function Expression?
When creating a Constructor Function, is it best practice to use a Function Declaration...
function Person(name, age) {
this.name = name;
this.age = age;
}
a Function Expression...
var Person = function(name, age) {
this.name = name;
this.age = age;
};
or is it simply a matter of personal preference?
1 Answer
Dave McFarland
Treehouse TeacherIt's really just a matter of personal preference, though a team might decide on a standard way of doing it.
The style shown in the Airbnb JavaScript Styleguide uses a function declaration.
Christopher Aporta
24,258 PointsChristopher Aporta
24,258 PointsGot it. This styleguide is an awesome reference, and thanks for the quick response!
Dave McFarland
Treehouse TeacherDave McFarland
Treehouse TeacherYeah, the Airbnb is a well respected style guide in the industry.