bhylu.com

Advertisements

Object Constructors

A constructor called with new creates an instance. Each instance gets its own assigned fields.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

function Member(name) {
  this.name = name;
}
const member = new Member("Mira");
console.log(member.name);

What happens

The new member stores Mira.