From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introducing classes

Introducing classes - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Introducing classes

- [Instructor] Classes have long been used in object-oriented programming languages to encourage reusability. For example, if we created some sort of a class called chair, a chair would have certain characteristics and then we could create instances of that chair in our projects. As of around 2015, we now have a way to create and use classes with JavaScript and the syntax is pretty fun to use. So first, let's go ahead and create a class called Vehicle. In it, there's a constructor function and the constructor is basically just going to set up any properties that this class is going to use. So what types of things are common about a vehicle? Well, we're going to have a description of some sort and then a number of wheels. So inside of the constructor, we want to set the value of description to this.description and this.wheels to associate it with the class. Next, I'm going to create a custom method called…

Contents