Objects and classes

In Java, you create a class to represent a concept, for example, a User class. The User class has a constructor, some fields, and methods. And you use its constructor to instantiate a User object. And every object in Java is an instance of the associated class that provides code sharing among its instances. You can extend the User class to create, for example, a TeamMember class.

In JavaScript, there are several ways to create an object:

  • The Object() constructor method
  • The object literal method
  • The constructor function method
  • The Object.create() method
  • The creator function method
  • The ES6 class method

Let's look at each method one at a time.

The Object constructor method looks like this:

// Call the Object constructor ...

Get Building Applications with Spring 5 and Vue.js 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.