From the course: JavaScript Essential Training

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Object constructors

Object constructors

- [Instructor] While classes are the preferred tool for creating object templates, there is another shorter and less advanced way of doing the same thing, which relies on a basic function. It's called an object constructor function and you can see an example of it in the exercise files for this movie. Just like with the class, the object constructor uses a capitalized name to let us know this is a constructor function that produces new objects. The object constructor function captures the properties of the new object using its parameters and then defines and assigns values for each property and method using the this keyword and dot notation. So here we have this name and it's populated with the value from the name parameter that's passed to the function. You'll notice that the difference between the class and the object constructor function here is the methods live inside the main construction function, just like the…

Contents