From the course: Objects in JavaScript: A Dynamic Data Structure

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Constructor functions and 'new' operator

Constructor functions and 'new' operator - JavaScript Tutorial

From the course: Objects in JavaScript: A Dynamic Data Structure

Constructor functions and 'new' operator

This is great. This is wonderful. You have made it to video two of chapter two. This couldn't be greater. If you think I'm repeating the word this quite a bit, you are right. In this video, I'll cover the this keyword and what it points to pertaining to objects. I'll show you how to use the this keyword to assign properties to a new object. The this keyword is used with object function constructors. An object function constructor is a function that when invoked with the new keyword, creates the same type of object. Here is an example. I have declared a function person and it has four parameters. In the body of the function you see this.firstName is assigned to the value for first. Then this .lastName is assigned to the value for last. You can see the same is done for this.age and this.eyeColor, each being assigned to values taken as arguments. If you want to dig deeper and explore other ways that this can be used, I would recommend looking at MDM documentation and reviewing how this…

Contents