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 trialedgar robledo
6,067 Pointsain't this way the same thing as using ( class, constructor )
function Person(firstName,lastName,age,eyeColor) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.eyeColor = eyeColor;
this.changeName = function (name) {
this.lastName = name;
}
}
var myMother = new Person("Sally","Rally",48,"green");
1 Answer
Steven Parker
231,153 PointsAt heart, JavaScript is a prototype-based language, and this is an example of the conventional approach to creating an object.
The new "class" syntax just gives you a new way to do the same things but in a way that appears more similar to a truly class-based language.
So you're right, the object you create with either syntax is essentially the same.