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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.